• What are you working on? V2
    2,001 replies, posted
You use it to pre-process stuff, hence the name. The stuff is evaluated before compiling. [url]http://en.wikipedia.org/wiki/C_preprocessor[/url]
[QUOTE=Robber;17020720]For constants and not including something twice? Sorry, I'm not really used to C++.[/QUOTE] Yes. Obviously, it makes textual replacement easy.
After a lot of time of debugging, rewriting, fixing and adding, I have improved it a lot :v: [quote] Added file operations (open, close, read, write) Added function for parsing files Added check for duplicate variables so you don't get more variables with the same name(This could fuck up the script, because it always went for the first one with that name) Added pretty fucking awesome error handling, now tells you in what function and what line(in the script) the error occured, along with more detailed information about it. Before you could only use Jazz_Error() with strings, now you can format them too, like printf. Example from Str_Sub: [cpp]Jazz_Error( Instance, "Wrong argument type #1. Expected TYPE_STRING, got %s", Jazz_GetType( String ) );[/cpp] Which would be called in case this was parsed from "Hello.txt": [code]<165.02 +str_sub[/code] And would result in this error code: [code][Hello.txt:2] str_sub: Wrong argument type #1. Expected TYPE_STRING, got TYPE_NUMBER[/code] Fixed a memory corruption error in char arrays and variable names because I forgot to allocate a byte for \0 Started working on mathlib (only has add, sub, mul and div)[/quote] Example code: (The forward slashes are just there to make it easier to figure out what are comments and what is not, they do nothing and the comment would be ignored regardless. [code] //Open the file for writing <"new.txt" <"w" +file_open // Store the file handle in variable MyFile =MyFile // Write to the file <MyFile <"This is the string I want to write!" +file_write // Close the file, cause we need to read now <MyFile +file_close // Open the file for reading <"new.txt" <"r" +file_open // Store the file handle in the variable MyFile =MyFile // Read from the file <MyFile +file_read // Print the contents +str_print // Close the file again <MyFile +file_close [/code] What it does: Opens new.txt for writing, writes "This is the string I want to write!" to it, closes it, opens it in read mode, reads the text and prints it to the console
:golfclap:
This problem is so simple and it's pissing me off so much. It's embarrassing even to ask [cpp] if (cursorPosX >= xPosition && cursorPosX <= xPosition + width && cursorPosY >= yPosition && cursorPosY <= yPosition + height) { if (inputManager->IsMouseButtonJustPressed(INPUT_L_MOUSE)) { isCheckboxActivated = true; } if (isCheckboxActivated && inputManager->IsMouseButtonJustPressed(INPUT_L_MOUSE)) { isCheckboxActivated = false; } } [/cpp] If the mouse is in the area and left mouse is clicked, checkbox is on. I want to click again while the checkbox is on so it turns it off. It works fine when the second click is changed to right mouse button so what I think is happening is that it's being activated then deactivated. Is there something I'm not seeing here?
What's IsMouseButtonJustPressed - is it being polled or is it there to implement a cooldown-type thing?
[cpp] if (cursorPosX >= xPosition && cursorPosX <= xPosition + width && cursorPosY >= yPosition && cursorPosY <= yPosition + height) { if (inputManager->IsMouseButtonJustPressed(INPUT_L_MOUSE)) { if(isCheckboxActivated) { isCheckboxActivated = false; }else{ isCheckboxActivated = true; } } } [/cpp] Not got a IDE Handy so I can't test :p
I figured it out just as I asked for help [cpp] if (cursorPosX >= xPosition && cursorPosX <= xPosition + width && cursorPosY >= yPosition && cursorPosY <= yPosition + height) { if (inputManager->IsMouseButtonJustPressed(INPUT_L_MOUSE)) { if (isCheckboxActivated) { isCheckboxActivated = false; } else { isCheckboxActivated = true; } } } [/cpp] [editline]03:53PM[/editline] [QUOTE=Tezza1234;17023200][cpp] if (cursorPosX >= xPosition && cursorPosX <= xPosition + width && cursorPosY >= yPosition && cursorPosY <= yPosition + height) { if (inputManager->IsMouseButtonJustPressed(INPUT_L_MOUSE)) { if(isCheckboxActivated) { isCheckboxActivated = false; }else{ isCheckboxActivated = true; } } } [/cpp] Not got a IDE Handy so I can't test :p[/QUOTE] wait what.. Figured it out at the same time :D [editline]03:54PM[/editline] [QUOTE=HubmaN V2;17023165]What's IsMouseButtonJustPressed - is it being polled or is it there to implement a cooldown-type thing?[/QUOTE] I have a input handler that can check mouse positions, mouse clicks, things like that
[cpp] if (inputManager->IsMouseButtonJustPressed(INPUT_L_MOUSE) && cursorPosX >= xPosition && cursorPosX <= xPosition + width && cursorPosY >= yPosition && cursorPosY <= yPosition + height ) { isCheckboxActivated = !isCheckBoxActivated; }[/cpp] :sigh:
[QUOTE=jA_cOp;17027333][cpp] if (inputManager->IsMouseButtonJustPressed(INPUT_L_MOUSE) && cursorPosX >= xPosition && cursorPosX <= xPosition + width && cursorPosY >= yPosition && cursorPosY <= yPosition + height ) { isCheckboxActivated = !isCheckBoxActivated; }[/cpp] :sigh:[/QUOTE] Or that :downs:
[QUOTE=jA_cOp;17027333][cpp] if (inputManager->IsMouseButtonJustPressed(INPUT_L_MOUSE) && cursorPosX >= xPosition && cursorPosX <= xPosition + width && cursorPosY >= yPosition && cursorPosY <= yPosition + height ) { isCheckboxActivated = !isCheckBoxActivated; }[/cpp] :sigh:[/QUOTE] ooh thanks, can apply that to alot of stuff
[QUOTE=jA_cOp;17027333][cpp] if (inputManager->IsMouseButtonJustPressed(INPUT_L_MOUSE) && cursorPosX >= xPosition && cursorPosX <= xPosition + width && cursorPosY >= yPosition && cursorPosY <= yPosition + height ) { isCheckboxActivated = !isCheckBoxActivated; }[/cpp] :sigh:[/QUOTE] heh, never thought of that...
Such code would be more efficient , yes? - As there is no comparing and code jumps going on?
And just thought that isCheckboxActivated = !isCheckBoxActivated; can be isCheckboxActivated ^= true;
I'm making a full-fledged OS with pre-emptive multitasking, window messages, compilers and whatnot. In Gmod. I also seem to hold the record of how slowly can one do something while actually doing it.
[QUOTE=Nikita;17030736]I'm making a full-fledged OS with pre-emptive multitasking, window messages, compilers and whatnot. In Gmod. I also seem to hold the record of how slowly can one do something while actually doing it.[/QUOTE] Please do share any milestones you cross, your project sounds very interesting.
Buttons and checkboxes are now pretty much perfect [cpp] if (cursorPosX >= xPosition && cursorPosX <= xPosition + width && cursorPosY >= yPosition && cursorPosY <= yPosition + height) { isCursorOnCheckbox = true; } else { isCursorOnCheckbox = false; isMouseDownOnCheckbox = false; } if(inputManager->IsMouseButtonJustPressed(INPUT_L_MOUSE) && isCursorOnCheckbox) { isMouseDownOnCheckbox = true; } else if(inputManager->IsMouseButtonJustReleased(INPUT_L_MOUSE) && isCursorOnCheckbox && isMouseDownOnCheckbox) { isCheckboxActivated ^= true; if(isCheckboxActivated) activated.Invoke(); else if(!isCheckboxActivated) deactivated.Invoke(); isMouseDownOnCheckbox = false; } else if(!inputManager->IsMouseButtonDown(INPUT_L_MOUSE)) { isMouseDownOnCheckbox = false; } [/cpp] If anyone can shorten that and for it to do the same thing then go ahead. You don't have to, just a fun little thing if you're bored.
You should really raise an event whenever a mouse button is pressed and released instead of checking every frame on every GUI control. It'd make for a lot cleaner code, and less error-prone.
# if(isCheckboxActivated) # activated.Invoke(); # else if(!isCheckboxActivated) # deactivated.Invoke(); its a boolean....so if its not true, its false, so the 2nd if isnt needed, just the else
Code blocks! (Functions!) [code] { // Start a new code block =TempVar <TempVar <TempVar >math_add } // End codeblock, push it onto the stack in the form of a TYPE_BLOCK =double // Assign the first variable on the stack to "double", this would be our block above, so now double is actually a block of code. <3 >double // Execute double, this starts calling the above codeblock >str_print // Print the results (6.0000) [/code]
[QUOTE=Bang Train;17038159]# if(isCheckboxActivated) # activated.Invoke(); # else if(!isCheckboxActivated) # deactivated.Invoke(); its a boolean....so if its not true, its false, so the 2nd if isnt needed, just the else[/QUOTE] Oh yeah, thanks. Was tired at the time
Added comparison of variables, using the ?. It's kinda cheating cause all it does is add "cmp_" to the code after it, and call it like a function. "?=" is the same as ">cmp_=" To compare variables you push the two variables onto the stack, and the function you want to call in case the comparison is positive. You can also pass one variable and one function, in which case it will compare the variable to NULL Made a function for printing the contents of files really fast [code] { <File >file_read >str_print <File >file_close } =read { <"Couldn't read file" >str_print } =error_reading { =FileName <FileName <"r" >file_open =File <File <NULL <error_reading ?= <File <NULL <read ?!= } =print_file //This is the actual code right here, everything above is just functions used to print it. <"new.txt" >print_file [/code] And here's the complete source code of the library and host application: [URL=http://errur.com/f/Download.php?id=736][IMG]http://errur.com/f/images/u/736.png[/IMG][/URL] Enjoy.
Added Grand Central Dispatch support to my FileWalker app after hours of mangling with queues. RIP NSThread, I suppose.
Edumacating myself on the C# Station Tutorial.
Qurl, I'm really interrested in your progress. Since it's stuff like that, I would like to do when I get a little futher in C++. Currently stuck becouse of School taking all my time :(. What are you going to use your game for?
I managed to make something funky while I'm learning SFML: [img]http://img134.imageshack.us/img134/7785/screenshotzvr.jpg[/img] The colour trail is because the sprite image has a border with different colours and I'm not clearing the screen.
SFML in Lua :D [media]http://www.youtube.com/watch?v=57FlAphT5Pw&feature=channel_page[/media] I'm trying to make it as close to Garry's Mod code as possible. Here is an example code: [lua] anim.Clear("idle") //Create an animation named, "idle" anim.Add("idle",{Vector(1,1),Vector(71,1),Vector(141,1),Vector(211,1)},{Vector(69,79),Vector(139,79),Vector(209,79),Vector(279,79)}) //Our animation uses a sprite sheet so we take rectangular parts from it. Character = sprite.Create("media/korean.png") //Create a sprite, loads image from a table or adds to table, "media/korean.png" Character:SetSmooth(false) //When drawn, should edge be smoothed? Default as true. Character:SetPosition(Vector(0,0)) //Set position to a 2D vector. Character:ResetAnim("idle",0.25) //Will run the earlier defined animation at 0.25 playback speed. [/lua]
That looks good, really close to the c++ code. I see you also added animation for sprites.. nice.
[QUOTE=BoingBoing;17055258]SFML in Lua :D [url]http://www.youtube.com/watch?v=57FlAphT5Pw&feature=channel_page[/url] (What is the youtube BBcode? D:) [/QUOTE] [noparse][media]insert link here[/media][/noparse]
[QUOTE=Wickedgenius;17051561]I managed to make something funky while I'm learning SFML: [img]http://img134.imageshack.us/img134/7785/screenshotzvr.jpg[/img] The colour trail is because the sprite image has a border with different colours and I'm not clearing the screen.[/QUOTE] You know, you can get some crazy performance improvements by clearing only what has changed instead of the entire screen. If the whole screen changes, you won't get much performance, but other than that it's huge.
Sorry, you need to Log In to post a reply to this thread.