As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
Options

PA Programming Thread - The Best Servers Are The Ones You Don't Use

1555658606163

Posts

  • Options
    EtheaEthea Registered User regular
    edited March 2011
    EvilMonkey wrote: »
    Infidel wrote: »
    Or for that matter, just skip cntr and calculate your index like a real man.

    But seriously, why use division to calculate your X/Y/Z back from an integer when you already have them.
    I entirely ignored that section, this just gets odder and odder. We're through the looking glass here people!

    Edit: I've had entirely too much cold medication.

    I would calculate the value when requested and not store them all. If you find that calculating the coordinate is becoming an issue I would look at some form of dynamic algorithm that stores the previous computed results. The best part is that the X and Y values has a known ranges (0-50 and 0-2500 for a subset of the calculation).

    Edit:
    You could even remove the floor by doing an integer divide as that is the same.

    Ethea on
  • Options
    Joe KJoe K Registered User regular
    edited March 2011
    Okay no I am not that dumb. It's not actually as easy as all that. It throws no match errors all over he place, and echo $I after the set command throws a no match. Argh! It's something ridiculous to do with tcsh syntax I think. I appear to be destroying the variables instead of changing their content?

    Quick dirty hack time!

    set names='ls l cut -d.-f1 l uniq | sed s/$/[14]/'

    You may need to escape some characters (e.g. $)

    Still gives me a no match.[] appears to force it to look for wild cards for some stupid reason.

    Also I can't include a fucking space as a delimeter. Or newline. Or anything beyond more characters. Fucking scripting.

    . is a single character wildcard
    if you're actually looking for a '.'
    you need to escape it '\.'

    welcome to the wonderfully powerful, confusing world of regex.

    Joe K on
  • Options
    Joe KJoe K Registered User regular
    edited March 2011
    Infidel wrote: »
    Icemopper wrote: »
    So... I'm a little confused on Binary... I can figure out how to count to 9, but then apparently 10 does not come after that?

    Am I missing the point?

    Er, well 10 decimal is 1010 binary.

    You need to think about what a base does in a number system.

    458 written out actually means 4 hundreds, 5 tens, 8 ones. I'm sure you remember the lessons like that in grade school.

    Well 1010 binary is 1 eights, 0 fours, 1 twos, 0 ones. 1 eight + 1 two = ten.

    The place value is (base ^ place) with place starting at 0 on the right and going up one each step to the left.

    So the first digit (starting on the right) of any integer in any number system is the base to the power 0, which is always the "ones". After that it changes.

    10^0 = ones
    10^1 = tens
    10^2 = hundreds
    10^3 = thousands
    etc.

    If you start looking at hexadecimal, it's the same thing.

    16^0 = ones
    16^1 = sixteens
    etc.

    include 2's complement. http://en.wikipedia.org/wiki/Two's_complement

    Joe K on
  • Options
    durandal4532durandal4532 Registered User regular
    edited March 2011
    Infidel wrote: »
    Okay, finally have time to work on this again, still crazy.

    Set I = "$I"\"\[14\"

    Works fine and produces FILE"[14".

    Set I = "$I"\"\[14\]\"

    Throws a no match error. As far as I can tell because some asshole decided no one would really actually want to escape a pair of brackets in tcsh. Anyone see an obvious screwup?

    Try '[14]', single quotes.

    hmm. Now I get no error on set, but echo $I and set newnames=names'\ '$I both give a no match.

    Also for fuck's sake, work. Unblock PA. Other programming forums are shit for questions. I want to cut and paste!

    durandal4532 on
    Take a moment to donate what you can to Critical Resistance and Black Lives Matter.
  • Options
    FremFrem Registered User regular
    edited March 2011
    Joe K wrote: »
    Python is a good language to begin with. It's not gimped like Java and C#, and well, PHP is PHP...

    If you really want to dig on languages, learn c/c++

    I'm having a blast with Go, but there's quite a few rough edges and installing it is non-intuitive if you're not used to mercurial.

    Version control is a nice thing to have at least a passing familiarity with early on, though. Just so you know it's there. I don't know. My experience with SVN and GDB was sort of like that feeling you get when you're in a Zelda dungeon, and you know that sort sort of tool would be really useful, but you're not sure what.

    Then, upon finding and using the tool, you become a rabid fan and tell anyone who will listen to you about it.

    Python is a great language. It was my first "real" scripting language and it does, in fact, feel like flying. From my perspective, Go is a lot of fun primarily because it syntactically has so much in common with Python.

    Frem on
  • Options
    TavTav Irish Minister for DefenceRegistered User regular
    edited March 2011
    import java.util.Arrays;
    
    public class insertionSort
    {
    	
    
    	public void insertSort() 
    		{
    			int in, out;
    			int[] anArray = new int[10];
    			int size = anArray.length;
    			
    			for(out=1; out<size; out++)
    				{
    					int temp = anArray[out];
    					in = out;
    					
    					while(in > 0 && anArray[in-1] >= temp)
    						{
    							anArray[in] = anArray[in-1]; //insert item right
    							--in; //go one position left
    						}
    				anArray[in] = temp; //insert marked item
    				}
    		}
    
    
    public static void main (String[] args){
    	
    	int [] array = new int [13];
    	array[0] = 53;
    	array[1] = 22;
    	array[2] = 44;
    	array[3] = 75;
    	array[4] = 1;
    	
    	System.out.println(Arrays.toString(array));
    	array.insertSort();
    	System.out.println(Arrays.toString(array));
    	
    
    }
    }
    

    Right, I got the insertSort class off my lecturer (we're upto Bucket sorting, but I'm trailing behind in the class so he gave me some stuff to look over during the mid-term) but for some reason the "array.insertSort();" line gives me the error "cannot invoke insertSort on the array type[int]"

    Uuuuuuuh, what does this mean and how can I fix it? Google isn't being much help and my lecturer is in Malaysia for the next week so I can't ask him...

    Tav on
  • Options
    InfidelInfidel Heretic Registered User regular
    edited March 2011
    insertSort is a method that acts on an object of type insertionSort, since that is the class and how you defined it.

    It also is working on a local array, never taking external data, in its current form. anArray is just a zero-filled array.

    Infidel on
    OrokosPA.png
  • Options
    Joe KJoe K Registered User regular
    edited March 2011
    Infidel wrote: »
    Okay, finally have time to work on this again, still crazy.

    Set I = "$I"\"\[14\"

    Works fine and produces FILE"[14".

    Set I = "$I"\"\[14\]\"

    Throws a no match error. As far as I can tell because some asshole decided no one would really actually want to escape a pair of brackets in tcsh. Anyone see an obvious screwup?

    Try '[14]', single quotes.

    try using bash

    Joe K on
  • Options
    ecco the dolphinecco the dolphin Registered User regular
    edited March 2011
    Infidel wrote: »
    Okay, finally have time to work on this again, still crazy.

    Set I = "$I"\"\[14\"

    Works fine and produces FILE"[14".

    Set I = "$I"\"\[14\]\"

    Throws a no match error. As far as I can tell because some asshole decided no one would really actually want to escape a pair of brackets in tcsh. Anyone see an obvious screwup?

    Try '[14]', single quotes.

    hmm. Now I get no error on set, but echo $I and set newnames=names'\ '$I both give a no match.

    Also for fuck's sake, work. Unblock PA. Other programming forums are shit for questions. I want to cut and paste!

    Ah.

    I totally forgot.

    I think the variable is being assigned properly, but when you echo it back, it sees the square brackets and tries to evaluate them as special characters.

    e.g. bash equivalent:
    ~/tmp/aa
    $ ls  # Lists all files in this temp directory
    adsf  fdbsalf  test_files
    
    ~/tmp/aa
    $ TEST_VAR=\*  # Assign asterisk to TEST_VAR
    
    ~/tmp/aa
    $ echo $TEST_VAR    # Whoops - asterisk has been taken to mean wildcard
    adsf fdbsalf test_files
    
    ~/tmp/aa
    $ echo "$TEST_VAR"  # Ah, displays asterisk
    *
    

    Suggestion:

    When you echo back variables with special characters in them, put them in weak (double) quotes:

    echo "$I"
    set newnames=names'\ '"$I"

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • Options
    durandal4532durandal4532 Registered User regular
    edited March 2011
    Joe K wrote: »
    try using bash
    Don't even joke. My other workplace is so much saner about scripts. I got no control over it here, though.

    durandal4532 on
    Take a moment to donate what you can to Critical Resistance and Black Lives Matter.
  • Options
    Joe KJoe K Registered User regular
    edited March 2011
    Joe K wrote: »
    try using bash
    Don't even joke. My other workplace is so much saner about scripts. I got no control over it here, though.

    dude, i'd be chewing off my arm if someone decided that all scripting had to be done in tcsh. at least it isn't csh.

    Joe K on
  • Options
    TavTav Irish Minister for DefenceRegistered User regular
    edited March 2011
    Infidel wrote: »
    insertSort is a method that acts on an object of type insertionSort, since that is the class and how you defined it.

    It also is working on a local array, never taking external data, in its current form. anArray is just a zero-filled array.

    uh, this might sound stupid, but don't I write the method to apply to work on a local array and then just apply it to a non-local array?

    Also, I have no idea what you mean by "acts on an object of type insertionSort"

    Sorry if these questions are inane, but like I said, I'm a fair bit behind my class at the moment and my lecturer thought it would be a great idea for me to try and catch up by myself using only pseudocode and a book which doesn't have any mention of sorting in it.

    Tav on
  • Options
    InfidelInfidel Heretic Registered User regular
    edited March 2011
    Tav wrote: »
    Infidel wrote: »
    insertSort is a method that acts on an object of type insertionSort, since that is the class and how you defined it.

    It also is working on a local array, never taking external data, in its current form. anArray is just a zero-filled array.

    uh, this might sound stupid, but don't I write the method to apply to work on a local array and then just apply it to a non-local array?

    Also, I have no idea what you mean by "acts on an object of type insertionSort"

    Sorry if these questions are inane, but like I said, I'm a fair bit behind my class at the moment and my lecturer thought it would be a great idea for me to try and catch up by myself using only pseudocode and a book which doesn't have any mention of sorting in it.

    You need to catch up on what java classes and objects are then.

    Infidel on
    OrokosPA.png
  • Options
    durandal4532durandal4532 Registered User regular
    edited March 2011
    Infidel wrote: »
    Okay, finally have time to work on this again, still crazy.

    Set I = "$I"\"\[14\"

    Works fine and produces FILE"[14".

    Set I = "$I"\"\[14\]\"

    Throws a no match error. As far as I can tell because some asshole decided no one would really actually want to escape a pair of brackets in tcsh. Anyone see an obvious screwup?

    Try '[14]', single quotes.

    hmm. Now I get no error on set, but echo $I and set newnames=names'\ '$I both give a no match.

    Also for fuck's sake, work. Unblock PA. Other programming forums are shit for questions. I want to cut and paste!

    Ah.

    I totally forgot.

    I think the variable is being assigned properly, but when you echo it back, it sees the square brackets and tries to evaluate them as special characters.

    e.g. bash equivalent:
    ~/tmp/aa
    $ ls  # Lists all files in this temp directory
    adsf  fdbsalf  test_files
    
    ~/tmp/aa
    $ TEST_VAR=\*  # Assign asterisk to TEST_VAR
    
    ~/tmp/aa
    $ echo $TEST_VAR    # Whoops - asterisk has been taken to mean wildcard
    adsf fdbsalf test_files
    
    ~/tmp/aa
    $ echo "$TEST_VAR"  # Ah, displays asterisk
    *
    

    Suggestion:

    When you echo back variables with special characters in them, put them in weak (double) quotes:

    echo "$I"
    set newnames=names'\ '"$I"

    Ah! Now we're getting somewhere. The new error is "syntax error" on

    Set newnames=$newnames'\ '"$I"

    But only after two loops through.

    If I remove the escape-space, it says no match again.

    durandal4532 on
    Take a moment to donate what you can to Critical Resistance and Black Lives Matter.
  • Options
    ecco the dolphinecco the dolphin Registered User regular
    edited March 2011
    Ah! Now we're getting somewhere. The new error is "syntax error" on

    Set newnames=$newnames'\ '"$I"

    But only after two loops through.

    If I remove the escape-space, it says no match again.

    You might need to quote "$newnames" as well, because it'll contain square brackets after the first loop.

    Set newnames="$newnames $I"

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • Options
    durandal4532durandal4532 Registered User regular
    edited March 2011
    Ah! Now we're getting somewhere. The new error is "syntax error" on

    Set newnames=$newnames'\ '"$I"

    But only after two loops through.

    If I remove the escape-space, it says no match again.

    You might need to quote "$newnames" as well, because it'll contain square brackets after the first loop.

    Set newnames="$newnames $I"

    Ho Ho! Finally! Yeah I just ended up with

    Set newnames="$newnames"' '"$I"

    Followed by

    Set names ="$newnames"

    Now to double check against the kludgy version. And convince the boss that as a principle usable scripts that require little editing are a good plan and not an indulgence. And to switch to bash.

    durandal4532 on
    Take a moment to donate what you can to Critical Resistance and Black Lives Matter.
  • Options
    IcemopperIcemopper Registered User regular
    edited March 2011
    Could anyone provide a simple example of how bitwise math would be used in programming? I'm learning it, slowly, but I'm not sure I grasp yet how it is used.

    Edit: If the answer is too involved, don't worry, I'm still working toward figuring it out, and I'm sure I'll get there soon/someday.

    Icemopper on
  • Options
    bowenbowen How you doin'? Registered User regular
    edited March 2011
    The best and most obvious example is on enums.

    http://www.cplusplus.com/forum/general/1590/

    Obviously you can use math to do bit shifting too, which another example is storing a full ip address in an 32 bit int, and then using bit shifting/bit masking to pull out each octet. Bit shifting and masking are uncommon now-a-days though, at least in my experience. Obviously not always the case for some of the other programmers here.

    Bit flags are an efficient and elegant solution to having a whole bunch of variables, basically.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    EtheaEthea Registered User regular
    edited March 2011
    A good list of bit twiddling tricks.

    http://www-graphics.stanford.edu/~seander/bithacks.html

    Ethea on
  • Options
    durandal4532durandal4532 Registered User regular
    edited March 2011
    My OS course was all building a really simple faux-OS, and a ton of those low-level tasks with tiny tiny available space bring bit operations into stark relief.

    Also, for fucking real: the place I am currently working has a person in charge of their computer whatevers that literally chooses to not use variables. That's why I'm futzing with tcsh for so long, so that we can put a standardized file into a folder and perform a standard operation on it. We'll need to do this several dozen times at minimum, and their standing solution was "ls the filedname, copy-paste into the array by shrinking the xterm window so it displays them in a long list so it will fit right". New file? Well, just nedit the script and don't screw it up I swear to god. They literally think just editing the fucking script for each new operation is a pretty great idea.

    Man. I will drag these people into sense if it kills me. I mean for fuck's sake, why even have standardized systems of naming if you're never going to take advantage of the fact?

    durandal4532 on
    Take a moment to donate what you can to Critical Resistance and Black Lives Matter.
  • Options
    InfidelInfidel Heretic Registered User regular
    edited March 2011
    Icemopper wrote: »
    Could anyone provide a simple example of how bitwise math would be used in programming? I'm learning it, slowly, but I'm not sure I grasp yet how it is used.

    Edit: If the answer is too involved, don't worry, I'm still working toward figuring it out, and I'm sure I'll get there soon/someday.

    The example is every single thing your computer or device does.

    Whether you code with them directly or not depends on how abstracted you are and allowed to be. If you're programming in an environment where you aren't working with devices directly or don't need to worry about the overhead of the abstractions then you may not work with them much at all, like bowen.

    If you're doing networking, encryption, hashing, embedded systems, parallel algorithms, emulation, game engines, straight C, etc. etc. then you'll be using the shit out of them. When you're not using the shit out of them, it is only because someone else used the shit out of them for your benefit.

    So reap the benefits if you can! Just don't neglect that the low-level matters and that someone has to deal with it.

    Infidel on
    OrokosPA.png
  • Options
    LittleBootsLittleBoots Registered User regular
    edited March 2011
    Smasher wrote: »
    Actual I subtract the Mouse(x,y) from the sprites origin. If I do it the other way round it goes wonky on me.

    Having a new problem now:
    Maths are weird :(

    Judging by the behavior, the angle is being stored as a value from -pi to pi radians. Your code (or perhaps the code you're calling?) is interpolating between where the circle is currently facing and where it should be facing, but when your angle goes from pi-a to pi+b (for small values of a and b) the latter gets converted to -pi+b, and the angle has to go all the way down from pi-a to -pi+b.

    Probably the simplest way to fix this is to keep track of the previous angle and see if the difference between the old one and the new one is greater than pi; if it is, either add or subtract pi (if you went from pi to -pi or vice versa, respectively) when you're giving the interpolation code the value to interpolate to.

    I did something along those lines and it fixed it, THANKS!
            /// <summary>
            /// Called on mouse left click to calculate the angle of rotation for our sprite
            /// </summary>
            /// <param name="inVal">Mouse pointer location</param>
            void calcRotation(Vector2 inVal)
            {
    
                //We set our previous angle value to our 'current' angle value.
                previousAngle = currentAngle;
    
                //Get the tangent of our new angle. 
                Vector2 tan = new Vector2((circleLoc.Y - inVal.Y), (circleLoc.X - inVal.X));
                
                //Normalize our tangent
                tan.Normalize();
                
                //Get our new angle
                newAngle = (float)Math.Atan2(-tan.Y, tan.X);
    
    
                //If our previous angle was negative and our new angle greater than 90degrees...
                if (previousAngle < 0 && newAngle >= MathHelper.ToRadians(90))
                {   //...Calculate the total amout of degrees we need to rotate
    
                    //Here we find the difference our new and previous angles are from 180degrees (or Pi radians) and add them together.
                    totalRotation = ((float)Math.PI - Math.Abs(previousAngle)) + ((float)Math.PI - Math.Abs(newAngle));
    
                    //Makes our direction of rotation counter-clockwise
                    totalRotation *= -1;
    
                    //Add our differences we calculated to our previous angle to get the total amout of radians we need to rotate. 
                    totalRotation += previousAngle;
    
                }
                //Else if opposite the condition of above...
                else if (previousAngle > 0 && newAngle < MathHelper.ToRadians(-90))
                {
                    //Do exactly the same thing WITHOUT rotating counter-clockwise
                    totalRotation = ((float)Math.PI - Math.Abs(previousAngle)) + ((float)Math.PI - Math.Abs(newAngle));
    
                    totalRotation += previousAngle;
                }
                //If neither of the above conditions are met...
                else
                {
                    //...just SET IT AND (all together now) FORGET IT! (we're just letting spriteBatch.Draw handle the rotation as usual)
                    totalRotation = newAngle;
                }
    
                
            }
            
            /// <summary>
            /// Called every tick. 
            /// Supposed to cause the sprite to 'rotate over time' but it's not working so good yet. 
            /// </summary>
            void updateRotation()
            {
                
                if (totalRotation < 0 && currentAngle != newAngle)
                {
                    if (currentAngle > totalRotation)
                    {
                        currentAngle += totalRotation / 10;
                    }
                    if (currentAngle < totalRotation)
                    {
                        currentAngle = newAngle;
                    }
                }
    
                if (totalRotation > 0 && currentAngle != newAngle)
                {
                    if (currentAngle < totalRotation)
                    {
                        currentAngle += totalRotation / 10;
                    }
                    if (currentAngle > totalRotation)
                    {
                        currentAngle = newAngle;
                    }
                }
            }
    

    Just need to figure out how to keep the rotation speed constant, as it currently is a bit wonky (some rotations seem instant some are extremely slow) but I'm getting there :D

    LittleBoots on

    Tofu wrote: Here be Littleboots, destroyer of threads and master of drunkposting.
  • Options
    Jimmy KingJimmy King Registered User regular
    edited March 2011
    ugh. Had a not so hot java/python interview today. The one good thing about those kind of interviews is that after I go home and read up on the stuff I screwed the pooch on, I won't forget it.

    I think we should start a New Wave of Perl Development movement. Changing to a new language as the core focus when you've been doing senior level development in a totally different language is kind of pain. I don't have the inside knowledge of Python or Java that I do of Perl, but I can still design a sane app and write it and can do so in any language you want me to with a some internet access and a couple of days.

    Jimmy King on
  • Options
    PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    edited March 2011
    Ethea wrote: »

    This really is a great list, I've used a bunch of these myself

    Phyphor on
  • Options
    InfidelInfidel Heretic Registered User regular
    edited March 2011
    LittleBoots, is updateRotation guaranteed to be called at a fixed interval? It very possibly isn't.

    Usually when you are doing animation, you scale things by the time-elapsed since the previous frame, so that you are not tied to the actual framerate or affected by spikes. Framerate independence is key in games and in UIs both. You want to be able to define something in seconds/milliseconds, not frames or other absolute units.

    For example, say timeElapsed is given in seconds. I would write an update for a translation from P1 to P2 something like:
    void translate(point P1, point P2, double howLong)
    {
      x = P1.x;
      y = P1.y;
      dx = P2.x - P1.x;
      dy = P2.y - P1.y;
      elapsed = 0;
      duration = howLong;
    }
    
    void update(double timeElapsed)
    {
      if (elapsed < duration)
      {
        elapsed += timeElapsed;
        x += dx * elapsed / duration;
        y += dy * elapsed / duration;
      }
    }
    

    Just an example on how you can use units of time with your objects to ensure consistent and easier-to-define behaviour, I'd recommend much more robust classes for handling all sorts of effects and manipulations. You would probably want to account for overshooting the destination, for one.
    Jimmy King wrote: »
    ugh. Had a not so hot java/python interview today. The one good thing about those kind of interviews is that after I go home and read up on the stuff I screwed the pooch on, I won't forget it.

    I think we should start a New Wave of Perl Development movement. Changing to a new language as the core focus when you've been doing senior level development in a totally different language is kind of pain. I don't have the inside knowledge of Python or Java that I do of Perl, but I can still design a sane app and write it and can do so in any language you want me to with a some internet access and a couple of days.

    Can I ask for more details? What did they pull out?

    Infidel on
    OrokosPA.png
  • Options
    IcemopperIcemopper Registered User regular
    edited March 2011
    Infidel wrote: »
    Icemopper wrote: »
    Could anyone provide a simple example of how bitwise math would be used in programming? I'm learning it, slowly, but I'm not sure I grasp yet how it is used.

    Edit: If the answer is too involved, don't worry, I'm still working toward figuring it out, and I'm sure I'll get there soon/someday.

    The example is every single thing your computer or device does.

    Well, yeah. I guess what I mean is, can you show me an example of it being used in code?

    Maybe I already have a basic grasp, let me give it a shot. Can I say that 0000 = red, blue, yellow, green, and starting with nothing, then adding a blue, say add 0100?

    Is that extremely basic/correct?

    From there I could see other uses if I'm headed in the right direction, I just don't want to forge ahead with the wrong mindset.


    EDIT: Also, I heard that it is used to call something from RAM because a binary set designates the location of that data, correct?

    Icemopper on
  • Options
    InfidelInfidel Heretic Registered User regular
    edited March 2011
    Icemopper wrote: »
    Infidel wrote: »
    Icemopper wrote: »
    Could anyone provide a simple example of how bitwise math would be used in programming? I'm learning it, slowly, but I'm not sure I grasp yet how it is used.

    Edit: If the answer is too involved, don't worry, I'm still working toward figuring it out, and I'm sure I'll get there soon/someday.

    The example is every single thing your computer or device does.

    Well, yeah. I guess what I mean is, can you show me an example of it being used in code?

    Maybe I already have a basic grasp, let me give it a shot. Can I say that 0000 = red, blue, yellow, green, and starting with nothing, then adding a blue, say add 0100?

    Is that extremely basic/correct?

    From there I could see other uses if I'm headed in the right direction, I just don't want to forge ahead with the wrong mindset.

    Yes, that is a set. You have four items, you can have each in the set or not in the set, using bits for that is a very common and efficient (the most efficient) way. Limitation is of course the number of items represented by the set, as that number gets larger it becomes less and less practical to do it this way.

    As an example of what I mean, there is no reason I couldn't make a set class that models this without using bit mapping. Even if I did, maybe you use it, and the bit mapping is transparent to you, since you shouldn't have to worry about the internal implementation of my data structure. Just treat it like a set.

    The basic bit mapping stuff you'll want to know if you are going to work with them are the simple operations of set and clear. Learn how to properly set any arbitrary bit in a set, and clear any arbitrary bit in a set (while leaving the other bits as-is).

    It's not hard, but you'd be amazed at how many programmers can't do it right. It's the basic operation for bit manip / digital logic, and all you need to implement a Set data structure (with the addition to being able to test to make it useful at all, so set/clear/test).

    Infidel on
    OrokosPA.png
  • Options
    LittleBootsLittleBoots Registered User regular
    edited March 2011
    I'm using XNA so it's supposed to be called in a fixed time step.

    LittleBoots on

    Tofu wrote: Here be Littleboots, destroyer of threads and master of drunkposting.
  • Options
    InfidelInfidel Heretic Registered User regular
    edited March 2011
    I'm using XNA so it's supposed to be called in a fixed time step.

    That is not a guarantee. Note that the parameter for the global Update is the actual elapsed game time.

    http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.update.aspx

    You should be passing that along and using it, that is why it is there!

    Infidel on
    OrokosPA.png
  • Options
    IcemopperIcemopper Registered User regular
    edited March 2011
    Ok, I think that makes sense. So that's how I put &, |, and ~ to use at times?

    Icemopper on
  • Options
    InfidelInfidel Heretic Registered User regular
    edited March 2011
    Icemopper wrote: »
    Ok, I think that makes sense. So that's how I put &, |, and ~ to use at times?

    Yep, you'll use them all. Give it a shot, if you like. :)

    You can even write a unit test, make sure your Set structure behaves as expected!

    Just a "script" that checks along the way, like:

    New Set
    Check Red false
    Check Blue false
    Check Green false
    Check Yellow false
    Set Blue
    Check Blue true
    Set Blue
    Check Red false
    Check Blue true
    Check Green false
    Check Yellow false
    etc.

    using the commands you implement.

    Infidel on
    OrokosPA.png
  • Options
    Jimmy KingJimmy King Registered User regular
    edited March 2011
    Infidel wrote: »
    Jimmy King wrote: »
    ugh. Had a not so hot java/python interview today. The one good thing about those kind of interviews is that after I go home and read up on the stuff I screwed the pooch on, I won't forget it.

    I think we should start a New Wave of Perl Development movement. Changing to a new language as the core focus when you've been doing senior level development in a totally different language is kind of pain. I don't have the inside knowledge of Python or Java that I do of Perl, but I can still design a sane app and write it and can do so in any language you want me to with a some internet access and a couple of days.

    Can I ask for more details? What did they pull out?

    Honestly, I don't think it was anything that crazy, just stuff I'm not familiar with or just don't see as an issue.

    The java one that got me was what is a static class and where would you use a static class. As a primarily Perl developer, hell if I know. I know what a static variable is and a static method is and have used both in Java stuff, but I've never used a static class.

    The python question question was more generic and so also a bit subjective. He just asked what my primary problems, if any, with Python are and then also said that there's one main thing as far as he is concerned. I don't really have any problems with the language beyond usage stuff such as easy_install pulling god knows what in from anywhere in the world or the knowledge of how it works internally TO have a problem with it. His problem with it is that it's dynamically typed, but I don't consider that a problem. He also said it's weakly typed, which it's not.

    Jimmy King on
  • Options
    InfidelInfidel Heretic Registered User regular
    edited March 2011
    Jimmy King wrote: »
    Infidel wrote: »
    Jimmy King wrote: »
    ugh. Had a not so hot java/python interview today. The one good thing about those kind of interviews is that after I go home and read up on the stuff I screwed the pooch on, I won't forget it.

    I think we should start a New Wave of Perl Development movement. Changing to a new language as the core focus when you've been doing senior level development in a totally different language is kind of pain. I don't have the inside knowledge of Python or Java that I do of Perl, but I can still design a sane app and write it and can do so in any language you want me to with a some internet access and a couple of days.

    Can I ask for more details? What did they pull out?

    Honestly, I don't think it was anything that crazy, just stuff I'm not familiar with or just don't see as an issue.

    The java one that got me was what is a static class and where would you use a static class. As a primarily Perl developer, hell if I know. I know what a static variable is and a static method is and have used both in Java stuff, but I've never used a static class.

    The python question question was more generic and so also a bit subjective. He just asked what my primary problems, if any, with Python are and then also said that there's one main thing as far as he is concerned. I don't really have any problems with the language beyond usage stuff such as easy_install pulling god knows what in from anywhere in the world or the knowledge of how it works internally TO have a problem with it. His problem with it is that it's dynamically typed, but I don't consider that a problem. He also said it's weakly typed, which it's not.

    The first one is a really stupid interview question. That is something I might expect if I was writing the SCJP, and only a maybe. Was their expected answer even correct, I wonder?

    The second is just laughable, "do you agree with my opinions?"

    You're better off.

    Infidel on
    OrokosPA.png
  • Options
    Jimmy KingJimmy King Registered User regular
    edited March 2011
    Infidel wrote: »
    Jimmy King wrote: »
    Infidel wrote: »
    Jimmy King wrote: »
    ugh. Had a not so hot java/python interview today. The one good thing about those kind of interviews is that after I go home and read up on the stuff I screwed the pooch on, I won't forget it.

    I think we should start a New Wave of Perl Development movement. Changing to a new language as the core focus when you've been doing senior level development in a totally different language is kind of pain. I don't have the inside knowledge of Python or Java that I do of Perl, but I can still design a sane app and write it and can do so in any language you want me to with a some internet access and a couple of days.

    Can I ask for more details? What did they pull out?

    Honestly, I don't think it was anything that crazy, just stuff I'm not familiar with or just don't see as an issue.

    The java one that got me was what is a static class and where would you use a static class. As a primarily Perl developer, hell if I know. I know what a static variable is and a static method is and have used both in Java stuff, but I've never used a static class.

    The python question question was more generic and so also a bit subjective. He just asked what my primary problems, if any, with Python are and then also said that there's one main thing as far as he is concerned. I don't really have any problems with the language beyond usage stuff such as easy_install pulling god knows what in from anywhere in the world or the knowledge of how it works internally TO have a problem with it. His problem with it is that it's dynamically typed, but I don't consider that a problem. He also said it's weakly typed, which it's not.

    The first one is a really stupid interview question. That is something I might expect if I was writing the SCJP, and only a maybe. Was their expected answer even correct, I wonder?

    The second is just laughable, "do you agree with my opinions?"

    You're better off.

    Yeah, I was primarily at this interview for the practice. I'm traditionally a bad interviewer anway - I get a bit nervous and stuttery and have a bad tendency to talk my skills down out of fear of BSing my way into something I can't do. This wasn't a job I really wanted after I got more details about it from the recruiter.

    It's at a startup which is currently fully funded by the founder and some of his friends from past business deals. Dev work just started in August, so the product isn't complete. No customers as of yet.

    The product itself is a good idea and the potential business deals they are working on sound really good, so there's potential. I've seen good potential get wasted by horrible implementation and rushed decision making way too many times at my current job to jump ship for "good potential" with no prior successes to gauge the chance of the current things on.

    Jimmy King on
  • Options
    LittleBootsLittleBoots Registered User regular
    edited March 2011
    Infidel wrote: »
    I'm using XNA so it's supposed to be called in a fixed time step.

    That is not a guarantee. Note that the parameter for the global Update is the actual elapsed game time.

    http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.update.aspx

    You should be passing that along and using it, that is why it is there!

    Hmm, so if I wanted to use the fixed time step that XNA is shooting for (16ms I believe) could I just do some like this?
            float targetElapsedTime = 16;
            float totalElapsedTime = 0;
    
            void myFunc(GameTime gameTime)
            {
                totalElapsedTime += gameTime.ElapsedGameTime.Milliseconds;
                if (totalElapsedTime => targetElapsedTime)
                {
                    doFoo();
                    totalElapsedTime = 0;
                }
    
            }
    

    LittleBoots on

    Tofu wrote: Here be Littleboots, destroyer of threads and master of drunkposting.
  • Options
    InfidelInfidel Heretic Registered User regular
    edited March 2011
    Infidel wrote: »
    I'm using XNA so it's supposed to be called in a fixed time step.

    That is not a guarantee. Note that the parameter for the global Update is the actual elapsed game time.

    http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.update.aspx

    You should be passing that along and using it, that is why it is there!

    Hmm, so if I wanted to use the fixed time step that XNA is shooting for (16ms I believe) could I just do some like this?
            float targetElapsedTime = 16;
            float totalElapsedTime = 0;
    
            void myFunc(GameTime gameTime)
            {
                totalElapsedTime += gameTime.ElapsedGameTime.Milliseconds;
                if (totalElapsedTime => targetElapsedTime)
                {
                    doFoo();
                    totalElapsedTime = 0;
                }
    
            }
    

    First, I think you meant TotalMilliseconds, not "just the milliseconds part please."

    The standard method is to grab the elapsed time (since the last time Update was called) as a value of seconds (it's a base unit, hail metric system.)

    The general idea is:
    double elapsedTime = gameTime.ElapsedGameTime.TotalSeconds;
    foreach (obj in myObjectsToUpdate)
    {
      if (!obj.update(elapsedTime)) myObjectsToUpdate.remove(obj);
    }
    

    as your main update pump and then:
    bool update(double elapsedTime)
    {
      // rotate based on elapsedTime
      // scale it and ignore any concept of "framerate", your code will now be completely framerate and even real/fixed time agnostic
      return !rotationDone;
    }
    

    where you handle whatever you need to for that object. In this case I'm having update return a value, returning true if I want to keep updating or false if I am done and don't need update to be called on this in the future (remove me from the active list). Keeps you from spending too long in your update logic, you want that to be efficient and avoid naive inefficiencies like calling a rotate update on an object that has stopped rotating.

    To start the rotation or whatever event you're animating, you'd initialize the appropriate parameters and then add it to your myObjectsToUpdate list.

    The reason to scale things by the actual elapsed time always, instead of what you did, is that you'll be losing and rounding off chunks, sometimes to a great degree. What happens if I call update with an elapsed time of two seconds? Is that really only 16ms worth of animation?

    Infidel on
    OrokosPA.png
  • Options
    LittleBootsLittleBoots Registered User regular
    edited March 2011
    DOH! Thanks for the heads up on the TotalMilliseconds, didn't even notice I was doing that.

    Also, that was a great explanation. I'll work on implementing some time scaling tomorrow.

    LittleBoots on

    Tofu wrote: Here be Littleboots, destroyer of threads and master of drunkposting.
  • Options
    EtheaEthea Registered User regular
    edited March 2011
    Jimmy King wrote: »
    Infidel wrote: »
    Jimmy King wrote: »
    ugh. Had a not so hot java/python interview today. The one good thing about those kind of interviews is that after I go home and read up on the stuff I screwed the pooch on, I won't forget it.

    I think we should start a New Wave of Perl Development movement. Changing to a new language as the core focus when you've been doing senior level development in a totally different language is kind of pain. I don't have the inside knowledge of Python or Java that I do of Perl, but I can still design a sane app and write it and can do so in any language you want me to with a some internet access and a couple of days.

    Can I ask for more details? What did they pull out?

    Honestly, I don't think it was anything that crazy, just stuff I'm not familiar with or just don't see as an issue.

    The java one that got me was what is a static class and where would you use a static class. As a primarily Perl developer, hell if I know. I know what a static variable is and a static method is and have used both in Java stuff, but I've never used a static class.

    The python question question was more generic and so also a bit subjective. He just asked what my primary problems, if any, with Python are and then also said that there's one main thing as far as he is concerned. I don't really have any problems with the language beyond usage stuff such as easy_install pulling god knows what in from anywhere in the world or the knowledge of how it works internally TO have a problem with it. His problem with it is that it's dynamically typed, but I don't consider that a problem. He also said it's weakly typed, which it's not.

    The greatest problem with python is the GIL ( Global Interpreter Lock ).

    Ethea on
  • Options
    Gandalf_the_CrazedGandalf_the_Crazed Vigilo ConfidoRegistered User regular
    edited March 2011
    You guys were right about the redundancy and weirdness in my coordinate system, but I already fixed it to this:
    for (z = 0; z < 10; z++)
                    for (y = 0; y < 50; y++)
                        for (x = 0; x < 50; x++)
                        {
                            Grid[x, y, z] = new Coordinate();
                            Grid[x, y, z].ID = i;
                            i++;
                            Grid[x, y, z].X = x;
                            Grid[x, y, z].Y = y;
                            Grid[x, y, z].Z = z;}
    

    I kept the ID number section in there, because why not, at this point. I may find some use for the ID, separate from the X,Y,Z values.

    Gandalf_the_Crazed on
    PEUsig_zps56da03ec.jpg
  • Options
    EndEnd Registered User regular
    edited March 2011
    Ethea wrote: »
    The greatest problem with python is the GIL ( Global Interpreter Lock ).

    heh, I was going to say this

    You can work around it in certain cases, but it's certainly a pretty large limiting issue with (C)Python.

    End on
    I wish that someway, somehow, that I could save every one of us
    zaleiria-by-lexxy-sig.jpg
This discussion has been closed.