1. Post #801
    Gold Member
    WTF Nuke's Avatar
    March 2009
    4,469 Posts
    Flub, I think it'll be easier if you just used std::cout rather than typing using std::cout. I might be wrong on this though, but I find it cleaner to just type std::cout rather than what you're doing.
    Reply With Quote Edit / Delete Windows 7 Canada Show Events

  2. Post #802
    Cesar Augusto's Avatar
    January 2010
    214 Posts
    Okay...Will work this ?

    Code:
    typedef struct student {
        char name[40+1];
        int idade;
        unsigned int n_reg; /* Number of register */
    } STUDENT;
    
    fwrite(&STUDENT, sizeof(STUDENT), 1, file);
    while ((fread(&STUDENT, sizeof(STUDENT), 1, file) == 1)
        fprintf(stdout, "Name: %s\nAge: %d\nNº reg.: %u\n", student->name, student->age, student->n_reg);
    Just look at "while"

    Damn...wrong button.... :´(
    Reply With Quote Edit / Delete Windows XP Brazil Show Events

  3. Post #803
    IndieGamer's Avatar
    February 2012
    65 Posts
    This it the code for my Save As button that iv made on my project.


    private void saveAsToolMenu_Click(object sender, EventArgs e)
    {
    saveFD.InitialDirectory = "C:";
    saveFD.Title = "save a text file";
    saveFD.FileName = "";

    saveFD.Filter = "Text Files|*.txt|All Files|*.*";

    if (saveFD.ShowDialog() != DialogResult.Cancel)

    Its works fine but i don't know what the code would be for the Save button where you don't actually choose a place to save it to it just updates the last save you made and saves it to that with out having to scroll through your files and folders. Can any one help?
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  4. Post #804
    Cesar Augusto's Avatar
    January 2010
    214 Posts
    Look at this part of my program

    Code:
    void Salvar(USUARIO *x)
    {
    	fseek(fp, 0L, SEEK_END);
    	if (fwrite(&x, sizeof(x), 1, fp) != 1)
    		{
    			fprintf(stderr, "Erro ao salvar o registro");
    			exit(1);
    		}
    	fprintf(stdout, "Registro salvo com sucesso!");
    }
    
    void ProcessOpen()
    {
    	if ((fp = fopen("Registros.dat", "wb")) == NULL)
    		{
    			fprintf(stderr, "Erro ao abrir o registro");
    			exit(1);
    		}
    }
    
    void Ler(USUARIO *x)
    {
    	rewind(fp);
    	while (fread(&x, sizeof(USUARIO), 1, fp))
    		fprintf(stdout, "Nome: %s\nSexo: %s\nIdade: %d\nTelefone: %d\nSalário: %.2f\nRegistrado: %d/%d/%d\n", x->nome, x->sexo, x->idade, x->telefone, x->salario, x->registrado.dia, x->registrado.mes, x->registrado.ano);
    }
    Works, but I want show each information of x person. Don't appears...

    Obs.: Some parts are in portuguese (dun worry)
    Reply With Quote Edit / Delete Windows XP Brazil Show Events

  5. Post #805
    Glorious GNU/Linux Master Race
    kaukassus's Avatar
    May 2010
    5,705 Posts
    I got a problem.

    I want to make a broadcast, that sends a String to every connected client. but when I execute the command, then I get the following error, at this point:

    Error:
    A disposed object can not be accessed.
    Object: "System.Net.Sockets.Socket".

    Code:
    Code:
    sent += socket.Send(buffer, offset + sent, size - sent, SocketFlags.None);
    The error probably only happens, when it tries to send the message to "127.0.0.1"


    Whole Network code:
    http://pastebin.com/D01U4GTy

    Execution code:
    Code:
            private void btn_send_01_Click(object sender, EventArgs e)
            {
                string str = "Teststring"; //String that gets send to the client
    
                foreach(ServerThread th in cNetListener.threads)
                {
                    Socket sck = th.connection.Client;
                    th.Send(sck, Encoding.UTF8.GetBytes(str), 0, str.Length, 1000);
                }
            }

    Also, can someone take a look at my network code, and tell me if the network shit I coded is bullshit?
    Reply With Quote Edit / Delete Mac Switzerland Show Events

  6. Post #806
    Richy19's Avatar
    May 2010
    5,407 Posts
    In C# how could i have a texture manager hold all the images and then have the classes point to the image they need? (while using safe code)
    In C+ I would do something like.
    MyClassImagePointer = TextureManager.GetImage(blah);

    But from what i can remember c# would create a copy of the image not a pointer to it
    Reply With Quote Edit / Delete Windows XP United Kingdom Show Events

  7. Post #807
    Capsup's Avatar
    April 2007
    822 Posts
    I've tried taking a look at my webgl project once again, and I just seem unable to find the problem... I'm sure I'm missing something really obvious but I just can't quite pinpoint it. Would anybody care to take a look at it and see if they can spot my mistake?
    The textured quads doesn't show up at all while the lines works fine. I'm also very certain that the texture is right as it works in my c++ opengl engine, but just not with webgl.

    Here's a link to it: http://dl.dropbox.com/u/40398697/Web...bGLProject.rar

    Any help is appreciated!
    Reply With Quote Edit / Delete Windows 7 Denmark Show Events

  8. Post #808
    NovembrDobby's Avatar
    April 2007
    1,157 Posts
    In C# how could i have a texture manager hold all the images and then have the classes point to the image they need? (while using safe code)
    In C+ I would do something like.
    MyClassImagePointer = TextureManager.GetImage(blah);

    But from what i can remember c# would create a copy of the image not a pointer to it
    C# is more likely to create a reference to it than a copy. You normally don't need to explicitly use pointers and ref objects.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Agree Agree x 1 (list)

  9. Post #809
    Gold Member
    ShaunOfTheLive's Avatar
    November 2007
    9,902 Posts
    C# is more likely to create a reference to it than a copy. You normally don't need to explicitly use pointers and ref objects.
    More specifically, all class objects in C# are reference types, not value types, just like in Java. Only value types (primitives and structs) get copied.
    Reply With Quote Edit / Delete Windows 7 Canada Show Events Agree Agree x 1 (list)

  10. Post #810
    Flubascrub
    Flubadoo's Avatar
    August 2009
    10,532 Posts
    Flub, I think it'll be easier if you just used std::cout rather than typing using std::cout. I might be wrong on this though, but I find it cleaner to just type std::cout rather than what you're doing.
    I mainly do it because I just want to keep a bunch of statements I'm gonna use at the beginning of every shitty program I write, so I don't have to rewrite it each time.

    Basically I just erase everything in int main(){} when I want to write a new program for practice.
    Reply With Quote Edit / Delete Windows 7 Qatar Show Events

  11. Post #811
    Jaykin' Bacon: Episode Three
    Jimbomcb's Avatar
    February 2005
    23,678 Posts
    It's a long shot, but in the source engine, anyone know why tracelines might not be registering hitboxes unless the traceline passes through the bbox of a player?

    I know for a fact this doesn't happen in dod:s for example, a player can be prone on the ground and their bounding box covers their torso at most yet the trace still impacts with the player hitboxes.

    Here's an example of it in my mod:


    You can see the bbox around the player, the hitboxes on the player and the white lines representing the traces. They don't register hitting the arm hitboxes because it was outside the bbox. If I turn around slightly and shoot at the same arm hitbox but make it clip through the edge of the bbox, it works as intended. Any ideas?
    Reply With Quote Edit / Delete Windows 7 Show Events

  12. Post #812
    Cesar Augusto's Avatar
    January 2010
    214 Posts
    Someone could help me how to use time.h ? Please. I want put automatically the time when the user data was registered.
    Reply With Quote Edit / Delete Windows XP Brazil Show Events Funny Funny x 1 (list)

  13. Post #813
    Gold Member
    Lord Ned's Avatar
    April 2006
    3,702 Posts
    It's a long shot, but in the source engine, anyone know why tracelines might not be registering hitboxes unless the traceline passes through the bbox of a player?

    I know for a fact this doesn't happen in dod:s for example, a player can be prone on the ground and their bounding box covers their torso at most yet the trace still impacts with the player hitboxes.

    Here's an example of it in my mod:


    You can see the bbox around the player, the hitboxes on the player and the white lines representing the traces. They don't register hitting the arm hitboxes because it was outside the bbox. If I turn around slightly and shoot at the same arm hitbox but make it clip through the edge of the bbox, it works as intended. Any ideas?
    It's probably because the Engine uses the Bounding Box as a fast pre-pass test. Since it never enters the bounding-box it never tests the hit boxes.

    Not sure there is an easy solution unfortunately. :(
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  14. Post #814
    Gold Member

    March 2005
    3,028 Posts
    So I've hit sort of a brick wall. I know what I want to do, I know how to do it in most sane languages (C, Python, Lua, etc.), but there isn't a single way to do it in Javascript that isn't fucking horrible.
    What I want to do is stop execution, then resume at the same point in code. Really, nothing more than a non-busy wait... something to indicate to the VM that it can take a break and go work on something else for a while. JS is probably the only language in the world that doesn't have such a thing, and, ironically, it's probably the only language in the world that really needs it, since you're sharing resources with lots of other JS programs and browsers don't have multitasking schedulers.

    The setTimeout solution for this particular problem is really filthy.
    Reply With Quote Edit / Delete Windows 7 Show Events Agree Agree x 1 (list)

  15. Post #815
    Richy19's Avatar
    May 2010
    5,407 Posts
    How was it that you get a point in say a 2d image using an index?

    I seem to remeber it was something like:

    x = i / width;
    y = i % width;
    Reply With Quote Edit / Delete Windows XP United Kingdom Show Events

  16. Post #816
    Gold Member

    March 2005
    3,028 Posts
    How was it that you get a point in say a 2d image using an index?

    I seem to remeber it was something like:

    x = i / width;
    y = i % width;
    It's either:
    x = i % w; y = i / w;
    or:
    y = i % h; x = i / h;

    Depending on whether your image is column-major or row-major.
    Reply With Quote Edit / Delete Windows 7 Show Events

  17. Post #817
    Iskuri's Avatar
    January 2009
    340 Posts
    2 C# questions, REALLY fucking urgent.

    First, how do I make it so a program opens a file in the software it's meant to be opened in (like a word document in word etc)

    Second, when using openxml, how do I stop the error where an edited excel file doesn't say it's unreadable when you try to open it afterwards and all the crap related to that. Thanks.
    Reply With Quote Edit / Delete Windows Vista United Kingdom Show Events

  18. Post #818
    Andrew McWatters
    Dennab
    March 2011
    4,658 Posts
    It's a long shot, but in the source engine, anyone know why tracelines might not be registering hitboxes unless the traceline passes through the bbox of a player?

    I know for a fact this doesn't happen in dod:s for example, a player can be prone on the ground and their bounding box covers their torso at most yet the trace still impacts with the player hitboxes.

    Here's an example of it in my mod:


    You can see the bbox around the player, the hitboxes on the player and the white lines representing the traces. They don't register hitting the arm hitboxes because it was outside the bbox. If I turn around slightly and shoot at the same arm hitbox but make it clip through the edge of the bbox, it works as intended. Any ideas?
    Sounds simply like you're not masking your trace correctly.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  19. Post #819
    Jaykin' Bacon: Episode Three
    Jimbomcb's Avatar
    February 2005
    23,678 Posts
    Sounds simply like you're not masking your trace correctly.
    The traces are being masked perfectly fine, I managed to find some of the engine level tracing stuff (from the hl2 leak by chance) and Lord Ned was right, it doesn't bother searching for hitboxes because it was using the bbox as a faster pre-pass test. Managed to work around it anyway.
    Reply With Quote Edit / Delete Windows 7 Show Events

  20. Post #820
    Hates php
    high's Avatar
    May 2006
    2,415 Posts
    -snip nevermind, cant read atm-
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  21. Post #821
    Gold Member
    Parakon's Avatar
    November 2008
    8,520 Posts
    I'm going to need some pathfinding but i'm not using tiles. So i'm thinking of using preset waypoints and just loop through them to find the closest to the target, and then move the NPC to the closest waypoint or something.

    Could I still use A* for something like that or what?
    Reply With Quote Edit / Delete Windows 7 Canada Show Events

  22. Post #822
    Gold Member
    WTF Nuke's Avatar
    March 2009
    4,469 Posts
    You can use A*, just make areas into nodes(they should be equal in size) and the NPCs will just follow the nodes to their destination node.
    Reply With Quote Edit / Delete Windows 7 Canada Show Events Useful Useful x 1 (list)

  23. Post #823
    Gold Member
    Eric95's Avatar
    January 2009
    5,031 Posts
    Snip, wrong thread
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events Funny Funny x 1 (list)

  24. Post #824
    evil-tedoz's Avatar
    October 2007
    129 Posts
    Hey guys, I need help with infix to prefix conversion, I understand the concept but I don't exactly know where to start out.
    Reply With Quote Edit / Delete Windows 7 Canada Show Events

  25. Post #825
    Gold Member
    Octave's Avatar
    January 2009
    2,530 Posts
    Hey guys, I need help with infix to prefix conversion, I understand the concept but I don't exactly know where to start out.
    For infix to RPN (postfix): http://en.wikipedia.org/wiki/Shunting_yard_algorithm
    I find that useful because RPN is easily parsed by a simple stack machine. You would probably be able to modify it a little bit to produce prefix, though.
    Reply With Quote Edit / Delete Linux United States Show Events Useful Useful x 1 (list)

  26. Post #826
    Gold Member
    Z_guy's Avatar
    July 2005
    594 Posts
    So, I need some help guys..

    I've made a resource manager, which scans a given folder and loads all the resources it can find. I also have a resource base class which have child classes for different kind of resources.

    My resource manager contains a factory to create resource instances of the different types.

    The problem I have is that when it finds a file, how does it know which kind of resource to instantiate?
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events

  27. Post #827
    evil-tedoz's Avatar
    October 2007
    129 Posts
    You could try to look for the extension, as in : .txt, .png, etc.
    Reply With Quote Edit / Delete Windows 7 Canada Show Events

  28. Post #828
    Gold Member
    Z_guy's Avatar
    July 2005
    594 Posts
    You could try to look for the extension, as in : .txt, .png, etc.
    My first solution was to allow the user to map simple wildcard patterns to resource types, like a "*.png" maps to a ImageResource, but then you can also do more advanced stuff like "map*.png", which would perhaps map to a MapResource. But then "map01.png" would match both the "*.png" and "map*.png", so which one should it choose?

    I'm not even sure I need that level of versatility
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events

  29. Post #829
    Gold Member
    Octave's Avatar
    January 2009
    2,530 Posts
    My first solution was to allow the user to map simple wildcard patterns to resource types, like a "*.png" maps to a ImageResource, but then you can also do more advanced stuff like "map*.png", which would perhaps map to a MapResource. But then "map01.png" would match both the "*.png" and "map*.png", so which one should it choose?

    I'm not even sure I need that level of versatility
    Just use nongreedy matching - that way the wildcard in map*.png will match anything it can up to .png but it won't match the .png.
    Reply With Quote Edit / Delete Linux United States Show Events

  30. Post #830
    Gold Member

    March 2005
    3,028 Posts
    The problem I have is that when it finds a file, how does it know which kind of resource to instantiate?
    For every supported resource type, include a type checker in addition to the loader. For binary formats, it's usually as simple as checking the magic number and version numbers.
    i.e.
    bool isbsp(uint8_t *data, int n) {
      if (n < 4) return false;
      return data[0] == 'I' && data[1] == 'B' && data[2] == 'S' && data[3] == 'P';
    }
    

    Then you do:
    if (isbsp(data, n))
      return loadbsp(data, n);
    if (ispng(data, n))
      return loadpng(data, n);
    if (isjpg(data, n))
      return loadjpg(data, n);
    // etc...
    

    Of course it's a little more difficult for plaintext formats. At that point you pretty much have to guess by the extension/source. I've never been a fan of file extensions, though.

    I wouldn't really go for wildcard-matching. I don't really have a good reason, it's just personal preference. I'd just split the last period-delimited substring off and check that against an extension string. IMHO, simpler, cleaner.
    Reply With Quote Edit / Delete Windows 7 Show Events

  31. Post #831
    Gold Member
    Z_guy's Avatar
    July 2005
    594 Posts
    For every supported resource type, include a type checker in addition to the loader. For binary formats, it's usually as simple as checking the magic number and version numbers.
    i.e.
    bool isbsp(uint8_t *data, int n) {
      if (n < 4) return false;
      return data[0] == 'I' && data[1] == 'B' && data[2] == 'S' && data[3] == 'P';
    }
    

    Then you do:
    if (isbsp(data, n))
      return loadbsp(data, n);
    if (ispng(data, n))
      return loadpng(data, n);
    if (isjpg(data, n))
      return loadjpg(data, n);
    // etc...
    

    Of course it's a little more difficult for plaintext formats. At that point you pretty much have to guess by the extension/source. I've never been a fan of file extensions, though.

    I wouldn't really go for wildcard-matching. I don't really have a good reason, it's just personal preference. I'd just split the last period-delimited substring off and check that against an extension string. IMHO, simpler, cleaner.
    Thank you, this was helpful, it got my cogs going again.
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events Friendly Friendly x 1 (list)

  32. Post #832
    RUBY OVERLORD
    swift and shift's Avatar
    November 2011
    2,115 Posts
    Only value types (primitives and structs) get copied.
    C# doesn't have any concept of 'primitives'
    Reply With Quote Edit / Delete Mac Australia Show Events Disagree Disagree x 2 (list)

  33. Post #833
    Andrew McWatters
    Dennab
    March 2011
    4,658 Posts
    The traces are being masked perfectly fine, I managed to find some of the engine level tracing stuff (from the hl2 leak by chance) and Lord Ned was right, it doesn't bother searching for hitboxes because it was using the bbox as a faster pre-pass test. Managed to work around it anyway.
    You'll find that there are a decent number of things with Source that are like this. You're best keeping an extracted copy of the leak for reference; I do and it helps a lot.

    Glad you found out the issue.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  34. Post #834
    Flubascrub
    Flubadoo's Avatar
    August 2009
    10,532 Posts
    What does it mean to "return f( x, y, z )" as opposed to "return n" in a function, in C++, whereas f is a function?
    Reply With Quote Edit / Delete Windows 7 Qatar Show Events Funny Funny x 1 (list)

  35. Post #835
    Gold Member
    Octave's Avatar
    January 2009
    2,530 Posts
    What does it mean to "return f( x, y, z )" as opposed to "return n" in a function, in C++, whereas f is a function?
    It means return whatever the function f(x, y, z) returns
    Reply With Quote Edit / Delete Linux United States Show Events Informative Informative x 1 (list)

  36. Post #836
    Flubascrub
    Flubadoo's Avatar
    August 2009
    10,532 Posts
    So it runs the function f inside of the function where return f(x, y, z) was located?
    Reply With Quote Edit / Delete Windows 7 Qatar Show Events Agree Agree x 3 (list)

  37. Post #837

    May 2011
    213 Posts
    Any idea why this snippet of C code makes me unable to type anything in the console?

    char opt;
    do
    {
    	opt = getchar();
    } while (opt != 'e')
    
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  38. Post #838
    Gold Member
    esalaka's Avatar
    July 2007
    10,242 Posts
    why are you storing getchar in a char
    Reply With Quote Edit / Delete Linux Finland Show Events Agree Agree x 1 (list)

  39. Post #839

    May 2011
    213 Posts
    Fixed it, never mind. Didn't freeze - it just took a while the first time I ran the program which is weird.

    esalaka posted:
    why are you storing getchar in a char
    I omitted the other code that comes in after "opt = getchar()" in the loop because it wasn't relevant to the problem.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  40. Post #840
    Gold Member
    esalaka's Avatar
    July 2007
    10,242 Posts
    opt should still be an int.
    Reply With Quote Edit / Delete Linux Finland Show Events Agree Agree x 1 (list)