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/
We're funding a new Acquisitions Incorporated series on Kickstarter right now! Check it out at https://www.kickstarter.com/projects/pennyarcade/acquisitions-incorporated-the-series-2

#define THREAD_TITLE "PA Programming Thread"

1404143454662

Posts

  • KakodaimonosKakodaimonos Code fondler Helping the 1% get richerRegistered User regular
    edited September 2010
    What is this COM lib written in?

    Kakodaimonos on
  • bowenbowen How you doin'? Registered User regular
    edited September 2010
    C#. We've never had issues with previous COM interop between foxpro and C# though. We have quite a few. This is just the one-off one that happens to be a form control. Though, trying to manually place it in code produces the same errors.

    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
  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    edited September 2010
    Lux782 wrote: »
    I have a question for everyone.

    How would you go about writing a function that handles drawing some polygon (by user input) and then deciding what is inside the polygon and what is outside and automatically filling the inside area in with some color.

    Are you talking generic 2d pixel manipulation, or drawing using some API?

    Is the polygon guaranteed convex? Non-overlapping?

    Phyphor on
  • KakodaimonosKakodaimonos Code fondler Helping the 1% get richerRegistered User regular
    edited September 2010
    Hmm. So you're doing the whole TLBIMP junk on the .Net DLL after it's generated?

    Kakodaimonos on
  • bowenbowen How you doin'? Registered User regular
    edited September 2010
    Hmm. So you're doing the whole TLBIMP junk on the .Net DLL after it's generated?

    I'm assuming regasm handles that through COM. Foxpro is one of those weird languages where you can just call shit randomly and if it's not there, keep executing.

    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
  • peterdevorepeterdevore Registered User regular
    edited September 2010
    Lux782 wrote: »
    I have a question for everyone.

    How would you go about writing a function that handles drawing some polygon (by user input) and then deciding what is inside the polygon and what is outside and automatically filling the inside area in with some color.

    There are a few steps in drawing a filled polygon. The short version being 'transform the vertex coordinates to screen space coordinates' and then 'fill in the area defined by the vertices' (rasterization). Transformations are done with some vector math, rasterizing can be done in several ways. It's best to let your graphics library worry about that stuff though, if you're not sure how to implement a certain effect with the functions your graphics library provides, ask away.

    peterdevore on
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited September 2010
    bowen wrote: »
    C#. We've never had issues with previous COM interop between foxpro and C# though. We have quite a few. This is just the one-off one that happens to be a form control. Though, trying to manually place it in code produces the same errors.

    Dumb question, but you did set the [ComVisible] attribute and give the component a good GUID, right? :P

    GnomeTank on
    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, NintendoID: Brainling, FF14: Zillius Rosh SFV: Brainling
  • KakodaimonosKakodaimonos Code fondler Helping the 1% get richerRegistered User regular
    edited September 2010
    bowen wrote: »
    Question for you guys familiar with COM.

    I've got a COM library already registered on a system, I did some changes to it, and now when I try to use a form builder and drag the COM library onto the form I get:

    "OLE error code 0x80029c4a: Error loading type library/DLL."

    It works fine everywhere else as far as I can tell, but I can't get it into drag/drop state that the other developer needs it for.

    You've loaded the COM object into the FoxPro ActiveX imports in the FoxPro IDE?

    Kakodaimonos on
  • bowenbowen How you doin'? Registered User regular
    edited September 2010
    Yes and yes. Problem solved, I wrote him a foxpro native object. I mean. I lost my fucking mind learning foxpro in about 1 hour, but, wow. Thanks all who tried. That was fucking insane.

    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
  • His CorkinessHis Corkiness Registered User regular
    edited September 2010
    list<Person> personList;
    
    if(personList.empty())
    {
    	personList.push_front(IDcount);	//not sure if this is correct, was using "new Person(IDcount)" before
    	IDcount++;
    }
    
    If this code compiles, I'm guessing your Person class has a constructor that takes a single int. You should probably mark that constructor as 'explicit' (eg: 'explicit Person(int id)' in the declaration in the header file) as, if you don't, you're basically saying to the compiler: 'If at any point you need a Person but I've given you an int, feel free to use this constructor without me explicitly telling you to'. This can cause some very difficult-to-find bugs if you accidentally pass the wrong thing to a function, because the compiler won't tell you that you accidentally passed an int, and you'll end up creating a new Person instead of copying another one, for instance. It won't affect your example here, but it's something to keep in mind whenever you write a constructor that takes a single argument.

    If you do mark the constructor as explicit, you can create a Person object from the int as such:
    personList.push_front(Person(IDcount));
    

    His Corkiness on
  • Simjanes2kSimjanes2k Registered User regular
    edited September 2010
    Weird question that I may have asked before: Does anyone else here toy with electronics as a hobby, and perhaps extend that into microchip programming in assembly? Maybe?

    Simjanes2k on
  • CangoFettCangoFett Registered User regular
    edited September 2010
    can anyone reccomend at c++ OOP/Classes tutorial that is

    a) free
    b) not retarded
    c) makes sense
    d) something else that is good
    e) nothing else that is bad.
    f) explains why this is useful.

    edit: mainly the whole private/public data storage thing.

    CangoFett on
  • PapillonPapillon Registered User regular
    edited September 2010
    Simjanes2k wrote: »
    Weird question that I may have asked before: Does anyone else here toy with electronics as a hobby, and perhaps extend that into microchip programming in assembly? Maybe?

    I learned 68HC11 assembler programming mostly for fun.

    And was then really bored when I had a course on HC11 programming.

    Papillon on
  • Sir CarcassSir Carcass I have been shown the end of my world Round Rock, TXRegistered User regular
    edited September 2010
    list<Person> personList;
    
    if(personList.empty())
    {
    	personList.push_front(IDcount);	//not sure if this is correct, was using "new Person(IDcount)" before
    	IDcount++;
    }
    
    If this code compiles, I'm guessing your Person class has a constructor that takes a single int. You should probably mark that constructor as 'explicit' (eg: 'explicit Person(int id)' in the declaration in the header file) as, if you don't, you're basically saying to the compiler: 'If at any point you need a Person but I've given you an int, feel free to use this constructor without me explicitly telling you to'. This can cause some very difficult-to-find bugs if you accidentally pass the wrong thing to a function, because the compiler won't tell you that you accidentally passed an int, and you'll end up creating a new Person instead of copying another one, for instance. It won't affect your example here, but it's something to keep in mind whenever you write a constructor that takes a single argument.

    If you do mark the constructor as explicit, you can create a Person object from the int as such:
    personList.push_front(Person(IDcount));
    

    Yeah, that was my hacky way of giving unique IDs to each new person created, and the constructor just assigns that int as their ID, defaulting the rest of their stuff. I'll look up explicit constructors, as I don't believe I've ever heard of that. Thanks for the info.

    Sir Carcass on
  • bowenbowen How you doin'? Registered User regular
    edited September 2010
    CangoFett wrote: »
    can anyone reccomend at c++ OOP/Classes tutorial that is

    a) free
    b) not retarded
    c) makes sense
    d) something else that is good
    e) nothing else that is bad.
    f) explains why this is useful.

    edit: mainly the whole private/public data storage thing.

    If all you want to know is public/private/protected I can tell you that.

    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
  • Sir CarcassSir Carcass I have been shown the end of my world Round Rock, TXRegistered User regular
    edited September 2010
    CangoFett wrote: »
    can anyone reccomend at c++ OOP/Classes tutorial that is

    a) free
    b) not retarded
    c) makes sense
    d) something else that is good
    e) nothing else that is bad.
    f) explains why this is useful.

    edit: mainly the whole private/public data storage thing.

    If you haven't already, try reading through these:

    http://www.cplusplus.com/doc/tutorial/classes/
    http://www.cplusplus.com/doc/tutorial/classes2/

    Sir Carcass on
  • KakodaimonosKakodaimonos Code fondler Helping the 1% get richerRegistered User regular
    edited September 2010
    bowen wrote: »
    Yes and yes. Problem solved, I wrote him a foxpro native object. I mean. I lost my fucking mind learning foxpro in about 1 hour, but, wow. Thanks all who tried. That was fucking insane.

    Why are you still using FoxPro? It is EOL from Microsoft and they're really suggesting that it won't play well at all with 64 bit down the road.

    Kakodaimonos on
  • bowenbowen How you doin'? Registered User regular
    edited September 2010
    Fortunately for my sanity, I'm not. I'm converting an application that was written in foxpro to .NET at this point in time. That control was really meant to be a hold over piece so new data they entered in the meantime would be in the new format. The other guy was completely lost as to how to implement the format natively so I just gave him access to a COM control. Turns out foxpro isn't really good with loading COM controls.

    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
  • templewulftemplewulf The Team Chump USARegistered User regular
    edited September 2010
    CangoFett wrote: »
    can anyone reccomend at c++ OOP/Classes tutorial that is

    a) free
    b) not retarded
    c) makes sense
    d) something else that is good
    e) nothing else that is bad.
    f) explains why this is useful.

    edit: mainly the whole private/public data storage thing.

    f) It's hard to see how these things play out differently without having worked in a multi-contributor production environment. Basically, OOP is one method of ensuring that somebody else's changes don't fuck up yours.

    It may seem like more work for identical results with what you're doing now, but it's one way to organize your code in a way that can withstand larger projects and teams.

    Edit:
    For example, at work we have an account data structure that is just awful. Code everywhere modifies it directly, which means that any change to the data structures or business rules for how we store private data forces us to change that code everywhere it appears in a system of millions of lines of code.

    In OOP-land, you make this data protected or private so that other code can't modify it. If I want to change a patient's address, I'd call patient->SetAddress('123 fake street'); This focuses all of the address rules into one function and lets us separate the act of setting an address from the details of implementing it.

    You can do similar things with data structures, well-planned functions and team conventions, but there aren't as many enforcement mechanisms. You just have to rely on your team not being tools, and that's harder than it sounds.

    templewulf on
    Twitch.tv/FiercePunchStudios | PSN | Steam | Discord | SFV CFN: templewulf
  • bowenbowen How you doin'? Registered User regular
    edited September 2010
    templewulf knows what he's talking about.

    Working by yourself? Not really much necessity for it until you look at code 6 months from now and wonder why the fuck you did what you did, because there's a totally better way to do it.

    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
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited September 2010
    Even when working on solo projects, I can't imagine not using good OO design principles, but that's probably because they've been hammered in to my head over the years.

    GnomeTank on
    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, NintendoID: Brainling, FF14: Zillius Rosh SFV: Brainling
  • Sir CarcassSir Carcass I have been shown the end of my world Round Rock, TXRegistered User regular
    edited September 2010
    bowen wrote: »
    templewulf knows what he's talking about.

    Working by yourself? Not really much necessity for it until you look at code 6 months from now and wonder why the fuck you did what you did, because there's a totally better way to do it.

    Man, I do that the next day.

    Sir Carcass on
  • MKRMKR Registered User regular
    edited September 2010
    Another use case in DB access. I have a db_engine.py that holds all the data models and provides functions for each kind of operation. It's not OO in the sense you'd normally think, where you inherit a class then do inheritedclass.method, but it serves the same purpose.

    The structure of the data is cordoned off from the implementation of the data. All the calling functions know is db_add_post(). They don't know whether it's using BigTable datastores, MySQL, or some perverse flat file horror.

    MKR on
  • ecco the dolphinecco the dolphin Registered User regular
    edited September 2010
    Simjanes2k wrote: »
    Weird question that I may have asked before: Does anyone else here toy with electronics as a hobby, and perhaps extend that into microchip programming in assembly? Maybe?

    Maybe, in time critical applications - e.g. using an AVR or the FIQ in an ARM for real time applications.

    But to be fair, even then, it was mostly convincing the C compiler to put locals in the appropriate registers as opposed to writing pure assembly.

    Failing that, fire up the CPLD/FPGA - responses in less than 1us without needing a high frequency clock! Whooo!

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • templewulftemplewulf The Team Chump USARegistered User regular
    edited September 2010
    GnomeTank wrote: »
    Even when working on solo projects, I can't imagine not using good OO design principles, but that's probably because they've been hammered in to my head over the years.

    Me too, but I think I have a problem. I'm mercilessly refactoring a facade class to a library object in a web app with only about 20 php files. :lol:

    templewulf on
    Twitch.tv/FiercePunchStudios | PSN | Steam | Discord | SFV CFN: templewulf
  • InfidelInfidel Heretic Registered User regular
    edited September 2010
    Simjanes2k wrote: »
    Weird question that I may have asked before: Does anyone else here toy with electronics as a hobby, and perhaps extend that into microchip programming in assembly? Maybe?

    Maybe, in time critical applications - e.g. using an AVR or the FIQ in an ARM for real time applications.

    But to be fair, even then, it was mostly convincing the C compiler to put locals in the appropriate registers as opposed to writing pure assembly.

    Failing that, fire up the CPLD/FPGA - responses in less than 1us without needing a high frequency clock! Whooo!

    Assembly? Pfffftt, that's for babies! Use gate logic like a real man.

    Infidel on
    OrokosPA.png
  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    edited September 2010
    What? You don't assemble the transistors by hand?

    Phyphor on
  • Sir CarcassSir Carcass I have been shown the end of my world Round Rock, TXRegistered User regular
    edited September 2010
    Alright, I started playing around with giving the tiles a person pointer but have run into a problem.

    Does the list class handle pointers to its objects in a weird way or something? I have it assign the pointer to the tile fine, but if I reorder the list with a function I wrote, it's like the pointer is now pointing to a different person. The problem may be with my reorder function, but I think I read something about lists and pointers and how after some operations the pointers can change.

    Sir Carcass on
  • bowenbowen How you doin'? Registered User regular
    edited September 2010
    It all depends on how you reorder them. If you change the actual values, then yes, it'll be a problem. If all you do is change the locations of next/previous in your list, then it is not so much of an issue, or shouldn't be. It's hard to say without code.

    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
  • Sir CarcassSir Carcass I have been shown the end of my world Round Rock, TXRegistered User regular
    edited September 2010
    This is my reorder function. Feel free to facepalm.
    		list<Person> tempList = personList;
    		int i = 1;
    		
    		for(list<Person>::iterator it=personList.begin();it!=personList.end();++it)
    		{
    			list<Person>::iterator it2 = tempList.begin();
    			while(it2->getID()!=i)
    				++it2;
    		
    			*it=*it2;
    			i++;
    		}
    

    Sir Carcass on
  • PapillonPapillon Registered User regular
    edited September 2010
    Alright, I started playing around with giving the tiles a person pointer but have run into a problem.

    Does the list class handle pointers to its objects in a weird way or something? I have it assign the pointer to the tile fine, but if I reorder the list with a function I wrote, it's like the pointer is now pointing to a different person. The problem may be with my reorder function, but I think I read something about lists and pointers and how after some operations the pointers can change.

    I assume this is C++. Don't put raw pointers into a STL container class; it will only end in tears. Mostly because you have to make sure that whenever you permanently remove an object from the class you also need to delete it.

    Instead you should either just put Person objects in the container directly (if your objects are reasonably small), or use a smart pointer like the smart_ptr class from the Boost library.

    Papillon on
  • Sir CarcassSir Carcass I have been shown the end of my world Round Rock, TXRegistered User regular
    edited September 2010
    Papillon wrote: »
    Alright, I started playing around with giving the tiles a person pointer but have run into a problem.

    Does the list class handle pointers to its objects in a weird way or something? I have it assign the pointer to the tile fine, but if I reorder the list with a function I wrote, it's like the pointer is now pointing to a different person. The problem may be with my reorder function, but I think I read something about lists and pointers and how after some operations the pointers can change.

    I assume this is C++. Don't put raw pointers into a STL container class; it will only end in tears. Mostly because you have to make sure that whenever you permanently remove an object from the class you also need to delete it.

    Instead you should either just put Person objects in the container directly (if your objects are reasonably small), or use a smart pointer like the smart_ptr class from the Boost library.

    If I'm understanding you correctly, then I must have misspoke. The list is of Person objects and I'm trying to store pointers to those individual objects in another class.

    Sir Carcass on
  • Simjanes2kSimjanes2k Registered User regular
    edited September 2010
    Infidel wrote: »
    Simjanes2k wrote: »
    Weird question that I may have asked before: Does anyone else here toy with electronics as a hobby, and perhaps extend that into microchip programming in assembly? Maybe?

    Maybe, in time critical applications - e.g. using an AVR or the FIQ in an ARM for real time applications.

    But to be fair, even then, it was mostly convincing the C compiler to put locals in the appropriate registers as opposed to writing pure assembly.

    Failing that, fire up the CPLD/FPGA - responses in less than 1us without needing a high frequency clock! Whooo!

    Assembly? Pfffftt, that's for babies! Use gate logic like a real man.

    Well, I do legitimately use assembly to cut down on the source for chips that drive small components, like an LCD that goes in a microphone or something. Have to use a cheap micro, a small micro, tiny LCD with tiny memory, etc. C compilers are great for making code easy, but it tends to take up an extra 20% or so space even at high efficiency compared to assembly.

    I was just wondering if anyone else had spent hours trimming lines of the stuff. Mind-numbing for hours, then exciting when you're done.

    Simjanes2k on
  • bowenbowen How you doin'? Registered User regular
    edited September 2010
    Ah gotta love C++ code. Any reason why you're using a List?

    I see you've got an ID there, I'd think a map/dictionary system would work better in that case.

    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
  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    edited September 2010
    The reordering is probably the problem. Any Person pointers to objects in that list become invalid.

    It also breaks if your IDs dont exactly run from 1 to N (ie, gaps).

    std::map will give you what you want easier and avoid copying like crazy too

    Phyphor on
  • Sir CarcassSir Carcass I have been shown the end of my world Round Rock, TXRegistered User regular
    edited September 2010
    Phyphor wrote: »
    The reordering is probably the problem. Any Person pointers to objects in that list become invalid.

    It also breaks if your IDs dont exactly run from 1 to N (ie, gaps).

    std::map will give you what you want easier and avoid copying like crazy too

    There shouldn't be gaps because I'm not deleting anyone once they've been created, but yeah, I could've shored that up a little.

    Bowen, you've suggested maps a couple of times for me, but I look at it and my brain kinda starts weeping and cursing my name. Looking at List was kinda the same way, though, so I guess I just need to play with it to figure out how to use it.

    Sir Carcass on
  • The AnonymousThe Anonymous Uh, uh, uhhhhhh... Uh, uh.Registered User regular
    edited September 2010
    It's funny. At first, I really, really hated AS3. Then it started to make sense, and I actually began to like it. Then while making changes to the movement logic, I try something like this:
    var wallCheckArea : ByteArray = maze.bitmapData.getPixels(new Rectangle(playerSprite.x, playerSprite.y - playerMovementSpeed, playerSprite.width, playerMovementSpeed));
    
    for (i = 0; i < wallCheckArea.length; i += playerSprite.width) {
    }
    
    playerSprite.y = (playerSprite.y <= playerMovementSpeed) ? 0 : playerSprite.y - playerMovementSpeed;
    

    and instead of the last line working as normal (i.e. moving up), the player bitmap magically jumps to the top of the screen. So yeah, AS3 is tons of (not) fun.

    The Anonymous on
  • DeathPrawnDeathPrawn Registered User regular
    edited September 2010
    Yeah, AS3 doesn't seem so bad until you start dealing with for loops. And then you hate it. And then you realize that you're hating a language because of the way it handles basic control flow.

    My favorite part of AS3's for loops (if I'm remembering this correctly, it's been a little while):
    for(i=0; i<10; i++) {
       trace(i);
    }
    

    will print out '10' ten times. However,
    for(i=0; i<10; i++) {
        foo(i);
    }
    
    function foo(i:Number):void {
       trace(i);
    }
    

    will behave as expected.

    DeathPrawn on
    Signature not found.
  • MKRMKR Registered User regular
    edited September 2010
    So what's the best way to to get rid of empty entries in an array of strings in python? I'm splitting something up (string.split) and it'll make my life easier if there are no empty entries.

    MKR on
  • jothkijothki Registered User regular
    edited September 2010
    Papillon wrote: »
    Alright, I started playing around with giving the tiles a person pointer but have run into a problem.

    Does the list class handle pointers to its objects in a weird way or something? I have it assign the pointer to the tile fine, but if I reorder the list with a function I wrote, it's like the pointer is now pointing to a different person. The problem may be with my reorder function, but I think I read something about lists and pointers and how after some operations the pointers can change.

    I assume this is C++. Don't put raw pointers into a STL container class; it will only end in tears. Mostly because you have to make sure that whenever you permanently remove an object from the class you also need to delete it.

    Instead you should either just put Person objects in the container directly (if your objects are reasonably small), or use a smart pointer like the smart_ptr class from the Boost library.

    If I'm understanding you correctly, then I must have misspoke. The list is of Person objects and I'm trying to store pointers to those individual objects in another class.

    I'm not sure how exactly those classes work behind the scenes, but I would not trust them to keep any sort of order in memory. They're designed to handle accessing through their own methods, not through any sort of outside access you might add in. If you want a linked list that stays relatively static in memory, actually program a linked list that does what you want.

    That, or completely ignore Papillion and go ahead and put pointers in the container instead of the raw objects. Deleting them individually isn't THAT much of a hassle, and lets you access the objects by other means without having to worry about them being moved around.

    jothki on
This discussion has been closed.