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/

PA Programming Thread :: PAdev.net - Need hosting for a service of yours? Check it out.

12467100

Posts

  • bowenbowen How you doin'? Registered User regular
    Last I heard they haven't done much with it. Would be fun to dick around with it. I think you're better off getting better results doing it yourself in C and then writing a C# parser of sorts and going from there. It'd probably get more done than any OS project.

    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
  • Joe KJoe K Registered User regular
    bowen wrote:
    Phyphor wrote:
    In my experience pointers confused the shit out of most people

    It's surprising really, that someone that's in comp-sci can be confused by the concept of what pointers are. The concept isn't sufficiently difficult but there are just some people that can't make sense of it.

    Then there's the difference between reference, pointer, and all that shit that just adds fuel to the fire.

    pointers and references should be pretty par for the course for any decent compsci program.

    where the real shit gets confusing is STL and Vectors.

  • bowenbowen How you doin'? Registered User regular
    Joe K wrote:
    bowen wrote:
    Phyphor wrote:
    In my experience pointers confused the shit out of most people

    It's surprising really, that someone that's in comp-sci can be confused by the concept of what pointers are. The concept isn't sufficiently difficult but there are just some people that can't make sense of it.

    Then there's the difference between reference, pointer, and all that shit that just adds fuel to the fire.

    pointers and references should be pretty par for the course for any decent compsci program.

    where the real shit gets confusing is STL and Vectors.

    I don't know, that stuff was comparatively easy. I'm not saying pointers and references are hard, but, the concepts behind them can confuse the fuck out of people.

    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
  • NightslyrNightslyr Registered User regular
    edited September 2011
    I just came across the idea of using output buffering to increase PHP script speed. Aside from the implicit buffering that Apache does, am I wrong in thinking that manually invoking the ob_* functions would be pointless in a MVC environment? I mean, by the time output is supposed to be rendered, all of the heavy lifting is done, with only simple view logic remaining.

    Nightslyr on
  • InfidelInfidel Heretic Registered User regular
    Yeah, that won't really affect performance. What those functions are good for performance wise is capturing the output so that you can implement caching of it, so that the heavy lifting is not done on every request, up-front is fine but it doesn't persist.

    OrokosPA.png
  • LindenLinden Registered User regular
    Jasconius wrote:
    Anyone here ever dick around with stuff like Phantom OS or http://en.wikipedia.org/wiki/Microsoft_Singularity ?

    This kind of stuff is fascinating to me. I think it would be so cool to have a whole new technology stack based on something other than UNIX.

    You might want to read about Synthesis as well. (Massalin, 1992)

  • Apothe0sisApothe0sis Have you ever questioned the nature of your reality? Registered User regular
    edited September 2011
    Familiarising myself with Python and loving it...

    Is there a way to call a specific attribute (this is the wrong term, isn't it?) or method from a variable like so:

    Like,
    >>> b.foo
    "bar"
    
    Can you do something like
    >>> a = "foo"
    >>> b.$a
    "bar"
    

    or something so that a is interpreted as an attribute or method name?

    I've been trying to google it or read through the language reference, but I'm not sure exactly what this would be called to check into it more efficiently.

    Apothe0sis on
  • Lux782Lux782 Registered User regular
    So, talking unit testing...

    How would you unit test the controls of a video game? Things like when A is pressed something happens? I was thinking of a class that you supply the key press and it alters an acceleration vector. Then I can test when a key is pressed the acceleration vector changes to what I expect it to be. However testing things like game logic might be more difficult. For collision detection I could setup a bunch of potential situations and determine if the objects collide. Anyone have any thoughts?

  • SeolSeol Registered User regular
    Lux782 wrote:
    How would you unit test the controls of a video game? Things like when A is pressed something happens? I was thinking of a class that you supply the key press and it alters an acceleration vector. Then I can test when a key is pressed the acceleration vector changes to what I expect it to be. However testing things like game logic might be more difficult. For collision detection I could setup a bunch of potential situations and determine if the objects collide. Anyone have any thoughts?
    Firstly, to unit test, make sure you're testing units. So if pressing A makes your character jump, then test that when your control class is given that input, that it invokes the jump() method on a mocked character. Then, separately, check that when the jump() method is invoked on your character, that the appropriate accelerations are applied.

    For collision detection, yeah: firstly check your collision classes by setting up various situations and seeing if they collide, then test your broad-phase algorithms by setting up mocks

    If you don't know how to unit test something because it's too big, or because there are too many steps between input and expected behaviour, that's a sign that you need smaller tests.

  • SeolSeol Registered User regular
    edited September 2011
    Doublepost :/

    Seol on
  • Jimmy KingJimmy King Registered User regular
    edited September 2011
    Apothe0sis wrote:
    Familiarising myself with Python and loving it...

    Is there a way to call a specific attribute (this is the wrong term, isn't it?) or method from a variable like so:

    Like,
    >>> b.foo
    "bar"
    
    Can you do something like
    >>> a = "foo"
    >>> b.$a
    "bar"
    

    or something so that a is interpreted as an attribute or method name?

    I've been trying to google it or read through the language reference, but I'm not sure exactly what this would be called to check into it more efficiently.

    This seems to be how to do it here. It's not quite as awesome of a solution as I'd expect from Python, but I guess it'll work.

    Looks like you can use eval() as well, but the above solution is safer.

    Jimmy King on
  • StarfuckStarfuck Registered User, ClubPA regular
    So yeah, diving into native node.js extensions and v8 engine is maybe a bit deep for a c++ novice. Lots of room to learn, but man, sometimes my eyes just glaze over looking over some of this source code.

    jackfaces
    "If you're going to play tiddly winks, play it with man hole covers."
    - John McCallum
  • Apothe0sisApothe0sis Have you ever questioned the nature of your reality? Registered User regular
    Jimmy King wrote:
    Apothe0sis wrote:
    Familiarising myself with Python and loving it...

    Is there a way to call a specific attribute (this is the wrong term, isn't it?) or method from a variable like so:

    Like,
    >>> b.foo
    "bar"
    
    Can you do something like
    >>> a = "foo"
    >>> b.$a
    "bar"
    

    or something so that a is interpreted as an attribute or method name?

    I've been trying to google it or read through the language reference, but I'm not sure exactly what this would be called to check into it more efficiently.

    This seems to be how to do it here. It's not quite as awesome of a solution as I'd expect from Python, but I guess it'll work.

    Looks like you can use eval() as well, but the above solution is safer.

    Looks preeeeetty good - certainly solves my problem. Thanks Jimmy!

  • The AnonymousThe Anonymous Uh, uh, uhhhhhh... Uh, uh.Registered User regular
    Jimmy King wrote:
    Looks like you can use eval() as well, but the above solution is safer.
    Pfft. Who needs code safety when you can have Python code in your Python code? :lol:

  • Jimmy KingJimmy King Registered User regular
    Jimmy King wrote:
    Looks like you can use eval() as well, but the above solution is safer.
    Pfft. Who needs code safety when you can have Python code in your Python code? :lol:
    I herd you liek... I can't do it.


  • The AnonymousThe Anonymous Uh, uh, uhhhhhh... Uh, uh.Registered User regular
    Jimmy King wrote:
    Jimmy King wrote:
    Looks like you can use eval() as well, but the above solution is safer.
    Pfft. Who needs code safety when you can have Python code in your Python code? :lol:
    I herd you liek... I can't do it.
    10230513.jpg

  • mr_michmr_mich Mmmmagic. MDRegistered User regular
    So, my JSP/servlet class is on headers and stuff now. I understand all that, but our prof makes a note that since servlets are multithreaded, we need to be careful of how we use our counters.

    Am I to assume I need to use a synchronize{} block to make my stuff thread-safe? Something like this:
    int pageViews;
    
    public void doGet(...){
      synchronize(pageViews){
         pageViews++;
         if(pageViews % 2 == 0)
           //output even number of pageviews
      }
    }
    

  • BarrakkethBarrakketh Registered User regular
    Apothe0sis wrote: »
    Familiarising myself with Python and loving it...

    Is there a way to call a specific attribute (this is the wrong term, isn't it?) or method from a variable like so:

    Like,
    >>> b.foo
    "bar"
    
    Can you do something like
    >>> a = "foo"
    >>> b.$a
    "bar"
    

    or something so that a is interpreted as an attribute or method name?.

    It's not the cleanest looking thing, but:
    b = Bar()
    b.foo()
    foo = getattr(b, "foo")
    foo()
    getattr(b, "foo")()
    

    If you inspect it you'll see something like:
    <bound method Foo.bar of <__main__.Foo instance at 0x03497B98>>
    

    Rollers are red, chargers are blue....omae wa mou shindeiru
  • PuddlesworthPuddlesworth Registered User regular
    Barrakketh wrote:
    Apothe0sis wrote: »
    Familiarising myself with Python and loving it...

    Is there a way to call a specific attribute (this is the wrong term, isn't it?) or method from a variable like so:

    Like,
    >>> b.foo
    "bar"
    
    Can you do something like
    >>> a = "foo"
    >>> b.$a
    "bar"
    

    or something so that a is interpreted as an attribute or method name?.

    It's not the cleanest looking thing, but:
    b = Bar()
    b.foo()
    foo = getattr(b, "foo")
    foo()
    getattr(b, "foo")()
    

    If you inspect it you'll see something like:
    <bound method Foo.bar of <__main__.Foo instance at 0x03497B98>>
    

    An if you're stll looking for another way you can even do
    >>> b.__dict__["foo"]
    "bar"
    

  • DrunkMcDrunkMc Registered User regular
    edited September 2011
    Hey guys, I have a java data structure question. I always find it hard to pick the most efficient one for what I'm doing. So I'm doing a flood_fill algorithm. http://en.wikipedia.org/wiki/Flood_fill The bottom one under Most Practical.

    I got it working but it was slow as shit. I was using a LinkedList<Pixel> as the queue because I knew I would be removing alot and figured that would be efficient. I was wrong, mainly because I check a lot to see if a pixel is already in the queue. (Because I'm doing an 8-way fill, not 4).

    So I implemented Comparable<Pixel> in my Pixel class and switched it to a TreeSet<Pixel> and it sped it up considerably but its still kind of slow. What is a good structure to house Pixels (double x, double y), where you will do many contains and removes and adds? Is TreeSet the best I'm going to do?

    Thanks!

    Oh, and the images I'm working on are ~3kx3k.

    DrunkMc on
  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    edited September 2011
    1) You can implement the list yourself and have each pixel object keep track of it's next/previous pointers. Testing for already being in the list becomes constant time.
    2) If you can't do that, use an array of bools or something to keep track of the insertion status of your pixels to reduce the time checking if it's already in the list and a stack for your list

    Also, you can try to use a further optimization of that algorithm: keep track of runs on the above/below pixels and only add one pixel per run to minimize list management overhead

    Phyphor on
  • DrunkMcDrunkMc Registered User regular
    edited September 2011
    Phyphor wrote:
    1) You can implement the list yourself and have each pixel object keep track of it's next/previous pointers. Testing for already being in the list becomes constant time.
    2) If you can't do that, use an array of bools or something to keep track of the insertion status of your pixels to reduce the time checking if it's already in the list and a stack for your list

    Also, you can try to use a further optimization of that algorithm: keep track of runs on the above/below pixels and only add one pixel per run to minimize list management overhead

    Really good ideas. With our special case, a co-worker actually thought of something that's similar to your #2. In my case, the images are a byte image, but we're only using 0 or 1. He had the idea of when adding to the queue, change that value to 2, and only go from 1 to 0 when you pop it off the queue. Then instead of structure.contains(pixel), I just have to see, pixels[x][y]!=2. Should be much much faster!

    If we didn't have this special case of 0 or 1, I'd def. do #2.

    Thanks!

    Update:
    In case anyone is interested, with using the image as an indicator as to whether a pixel was already on the queue, instead of doing a .contains() on the queue, the flood delete went from ~50% of the processing to 7% of the processing. And thats in the worst case sceneario. So, Woo! Interesting lesson learned!

    DrunkMc on
  • JediNightJediNight Registered User regular
    Anyone care to take a swing at pointing me in the right direction for a Java assignment? I've tried fixing my issues for several hours now and I keep hitting new snags related to the problem.

    Basically atm it's getting to the last element in the ArrayList and hanging with an ArrayList<E>RangeCheck error. The odd thing about it is that it correctly pulls the customer name from that row of the ArrayList then hangs on pulling the sales data when no new incrementing has occurred.

    Also maybe thoughts on my approach atm: I'm parsing an invoice list and putting it into an ArrayList and sorting it. Then going back through it to process the report and generate a total sales report for each warehouse and grand totals. Customer names appear multiple times in the sample sales DAT from the professor, so when its sorted they are clumped together (hence checking to see if the next name is the same).

    http://www.privatepaste.com/2ac2c1ac0c

  • EndEnd Registered User regular
    edited September 2011
    JediNight wrote: »

    I can't stop looking at this:
    if (moreCustomers = true) {
    

    edit: but...I can't see where moreCustomers is ever set to anything but true anyway

    End on
    I wish that someway, somehow, that I could save every one of us
    zaleiria-by-lexxy-sig.jpg
  • IncindiumIncindium Registered User regular
    Dude you are accessing the next element of the arraylist even when you are on the last element with your while
    while (arrayList.get(count).getCustName().equals(arrayList.get(count+1).getCustName())) {
    

    Not to be mean but that whole thing needs to be reworked a bit. Why don't you use for each on your arraylist
    and then reference the single Invoice object rather than looking it up from the arraylist for every method call?

    IE
    for (Invoice myinv : arrayList )
    {
    myinv.getWarehouse(); //or whatever
    myinv.getCost();
    }
    

    etc.

    steam_sig.png
    Nintendo ID: Incindium
    PSN: IncindiumX
  • JediNightJediNight Registered User regular
    edited September 2011
    End wrote:
    JediNight wrote: »

    I can't stop looking at this:
    if (moreCustomers = true) {
    

    edit: but...I can't see where moreCustomers is ever set to anything but true anyway

    Thats a code fragment from trying to fix my problems. I'll clean it up later.... Since it doesn't harm anything atm and I wasn't sure if I would need to re-implement it later I left it for now.

    Incindium: Thanks for pointing out the issue with the count+1. Should I make some kind of null check then? And I'll read up on foreach as well. This is the start of 2nd semester Java for me, so I don't know all of the ways to properly code yet. (Especially since most of my class is getting remedial review from the Professor while I work ahead and try to learn better ways of accomplishing the Projects. Pisses me off actually, because she's basically reteaching 1st semester to them while I pay for it...)

    EDIT: Would I be better off scrapping the entire idea of parsing and sorting the invoice file first? And just going with something like a binary search for a matching customer name when each new line is read from the invoice file and add that data to it?

    JediNight on
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited September 2011
    Foreach is a beautiful thing. It nukes a lot of off-by-one bounds errors that otherwise pop up when you are learning a new language (or to code at all).

    As a heads up, it looks like this in the languages I know and that have it:

    Java
    for(ThingType thing : box)
    

    C#
    foreach(var thing in box)
    

    Javascript
    for(var thing in box)
    

    Go
    for thing, index := range box
    

    The only catch is that you lose the index number (except in Go). Most of the time you don't need it, but occasionally you do and have to go back to the traditional for(int i = 0; i < x; i++) format.

    In Java you can do that with arrays and anything that implements Iterable

    Monkey Ball Warrior on
    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    foreach in pre-C++11!
    #define foreach(obj, ...) for(__VA_ARGS__::iterator it = (obj).begin(); it != (obj).end(); ++it)
    

  • admanbadmanb unionize your workplace Seattle, WARegistered User regular
  • FremFrem Registered User regular
    The only catch is that you lose the index number (except in Go). Most of the time you don't need it, but occasionally you do and have to go back to the traditional for(int i = 0; i < x; i++) format.

    It's also easy to get the index number in Python:
    for thing, index in enumerate(box):
    

  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    Frem wrote:
    The only catch is that you lose the index number (except in Go). Most of the time you don't need it, but occasionally you do and have to go back to the traditional for(int i = 0; i < x; i++) format.

    It's also easy to get the index number in Python:
    for thing, index in enumerate(box):
    

    Yeh I really need to sit down and learn python at some point.

    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • WeretacoWeretaco Cubicle Gangster Registered User regular
    You can retain it in c# enumerables too with little work and anonymous types.

    Unofficial PA IRC chat: #paforums at irc.slashnet.org
  • InfidelInfidel Heretic Registered User regular
    Phyphor is good people.

    OrokosPA.png
  • BarrakkethBarrakketh Registered User regular
    Frem wrote: »
    The only catch is that you lose the index number (except in Go). Most of the time you don't need it, but occasionally you do and have to go back to the traditional for(int i = 0; i < x; i++) format.

    It's also easy to get the index number in Python:
    for thing, index in enumerate(box):
    
    Umm...you have it backwards:
    for idx, thing in enumerate(box):
        stuff
    

    It also supports a start parameter in case you want to start counting from something other than 0.

    Rollers are red, chargers are blue....omae wa mou shindeiru
  • templewulftemplewulf The Team Chump USARegistered User regular
    Ugh. Am I wrong in thinking there is no reason that dictionaries aren't serializable in C#?

    I'm trying to save sprite sheet metadata to XML files with XNA. Does anyone have any suggestions for how to do this now that I can't just serializer.Serialize()? I'm not married to XML either, but I'd like to just implement a ready-made solution and get on with the interesting parts.

    Twitch.tv/FiercePunchStudios | PSN | Steam | Discord | SFV CFN: templewulf
  • InfidelInfidel Heretic Registered User regular
    templewulf wrote:
    Ugh. Am I wrong in thinking there is no reason that dictionaries aren't serializable in C#?

    I'm trying to save sprite sheet metadata to XML files with XNA. Does anyone have any suggestions for how to do this now that I can't just serializer.Serialize()? I'm not married to XML either, but I'd like to just implement a ready-made solution and get on with the interesting parts.

    They aren't XML serializable out of the gate, but you can do a few things.

    One would be to do a binary serialize of the dictionary object and then stuff that as binary data into a member that then is serialized by your overall XML process.

    Another would be to implement your own SerializableDictionary from Dictionary and IXmlSerializable.

    OrokosPA.png
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited September 2011
    Yeh I hit that little snag when trying to save dictionaries in Profiles in ASP.NET. (that and the fun that is specifying generic types in web.config) I ended up just specifying binary serialization and it worked out fine...

    ...except come to find out I didn't have anywhere to actually put the profile data since we use Oracle instead of MS SQL server at work and the backflips you have to perform to get that working ended up being incompatible with other weird things that we are doing with Oracle.

    tl;dr Oracle is weird.

    Monkey Ball Warrior on
    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • Alistair HuttonAlistair Hutton Dr EdinburghRegistered User regular
    Infidel wrote:
    templewulf wrote:
    Ugh. Am I wrong in thinking there is no reason that dictionaries aren't serializable in C#?

    I'm trying to save sprite sheet metadata to XML files with XNA. Does anyone have any suggestions for how to do this now that I can't just serializer.Serialize()? I'm not married to XML either, but I'd like to just implement a ready-made solution and get on with the interesting parts.

    They aren't XML serializable out of the gate, but you can do a few things.

    One would be to do a binary serialize of the dictionary object and then stuff that as binary data into a member that then is serialized by your overall XML process.

    Another would be to implement your own SerializableDictionary from Dictionary and IXmlSerializable.

    Or you can XML serialise a list of DictionaryEntry objects and then reconstruct the dictionary with them on deserialisation.

    I have a thoughtful and infrequently updated blog about games http://whatithinkaboutwhenithinkaboutgames.wordpress.com/

    I made a game, it has penguins in it. It's pay what you like on Gumroad.

    Currently Ebaying Nothing at all but I might do in the future.
  • bowenbowen How you doin'? Registered User regular
    Alistair's is probably the quickest to do.

    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
  • Jimmy KingJimmy King Registered User regular
    edited September 2011
    mmmm, foreach. I just had to go through a bunch of javascript at the new job written by an old C/C++ dev and turn for loops into foreach because there were off by one errors in all of them and they required manual fiddling any time new category thingies get added to the site. He's a smart guy, wrote multithreaded c++ stuff that works afaik, so just not up on this fancy newer stuff.

    btw, be careful with the "for(var thing in box)" style of foreach in js. If you're iterating over an Array(), with "for(var thing in box)" you're actually getting the keys because it iterates over the object's dictionary (or something like that). That shit gets me every damned time. JavaScript also has a proper Array.forEach() which returns the values rather than the keys/indexes but IE didn't support it until IE9 so it's not terribly useful.
      myArray = new Array();
      myArray[0] = "zero";
      myArray[1] = "one";
      myArray[2] = 2;
      myArray[3] = 3;
      myArray[4] = 4;
    
      myArray.forEach(function(x) { alert(x)});
    
     /* or if you also want the index, similar to python you can do this.  x and idx may be backwards*/
     myArray.forEach(function(x, idx) {alert("Index is " + idx + " and value is " + x);
    

    Jimmy King on
This discussion has been closed.