• What Do You Need Help With? V8
    1,074 replies, posted
Another weird problem. Cleaned up the code, got to this: [code]//Dialogue box class DialogueBox : public GUIElement { private: std::wstring lastText; int curChar; int curLine = 1; GUIText textElement[2]; //Draw background box void drawBg() { //Background box glColor3f(1.0f, 1.0f, 0.8f); glBegin(GL_POLYGON); glVertex2i(outlineRect.x, outlineRect.y); glVertex2i(outlineRect.x + outlineRect.w, outlineRect.y); glVertex2i(outlineRect.x + outlineRect.w, outlineRect.y + outlineRect.h); glVertex2i(outlineRect.x, outlineRect.y + outlineRect.h); glEnd(); //Outline glLineWidth(2.0f); glColor3f(0.2f, 0.4f, 0.8f); glBegin(GL_LINE_LOOP); glVertex2i(outlineRect.x, outlineRect.y); glVertex2i(outlineRect.x + outlineRect.w, outlineRect.y); glVertex2i(outlineRect.x + outlineRect.w, outlineRect.y + outlineRect.h); glVertex2i(outlineRect.x, outlineRect.y + outlineRect.h); glEnd(); } public: std::wstring text; //Draw box and text void draw(float delta) { calcOutlineRect(); drawBg(); //Check if given string changed, reset variables if so if (lastText != text) { curChar = 0; curLine = 1; textElement[1].text = L""; textElement[2].text = L""; } //Append next character to displayed string if (curChar < text.length()) { if (text[curChar] == '\n') curLine++; //Go to next line if current character is newline else textElement[curLine].text += text[curChar]; //Otherwise append next character to the string curChar++; } //Draw each text line for (int i = 1; i <= 2; i++) { if (textElement[i].text != L"") { textElement[i].x = outlineRect.x + 8; textElement[i].y = outlineRect.y + 8 + 32 * i - 32; textElement[i].fontFile = "ipaexg.ttf"; textElement[i].size = 32; textElement[i].fgcolor = { 0, 0, 0 }; textElement[i].draw(); } } lastText = text; } }; [/code] But now Visual Studio tells me this when it gets to the newline: [quote]Exception thrown: read access violation. _S2 was 0x30. If there is a handler for this exception, the program may be safely continued.[/quote] It seems this line of code is the culprit because no exceptions are thrown if I comment it out: [code]if (text[curChar] == '\n') curLine++;[/code] But of course without that line of code it will not go to the next line of the string. What do I do?
nvm
[QUOTE=daigennki;52488242]Another weird problem. [...][/QUOTE] Are you sure your [I]text[/I] never contains more than one [I]'\n'[/I] that's directly or indirectly followed by any other character? There doesn't seem to be any validation for that/[I]curLine[/I], so any [I]text[/I] like that will eventually make your code go out of bounds on [I]else textElement[B][[/B]curLine[B]][/B].text += text[curChar];[/I]. I suspect the segfault itself only triggers a little later, either when accessing [I].text[/I] or applying the operator (if that really makes a difference. I don't use C++ myself, so grain of salt as usual). [editline]20th July 2017[/editline] A small criticism if you weren't already planning to change this: Please don't lock your text speed to the frame rate.
[QUOTE=Tamschi;52488424]Are you sure your [I]text[/I] never contains more than one [I]'\n'[/I] that's directly or indirectly followed by any other character? There doesn't seem to be any validation for that/[I]curLine[/I], so any [I]text[/I] like that will eventually make your code go out of bounds on [I]else textElement[B][[/B]curLine[B]][/B].text += text[curChar];[/I]. I suspect the segfault itself only triggers a little later, either when accessing [I].text[/I] or applying the operator (if that really makes a difference. I don't use C++ myself, so grain of salt as usual).[/QUOTE] Okay, added validation for [I]curLine[/I], now looks like this: [code]if (text[curChar] == L'\n' && curLine == 1) curLine++; //Go to next line if current character is newline else textElement[curLine].text += text[curChar]; //Otherwise append next character to the string[/code] Still getting the same exception though. [editline]20th July 2017[/editline] And yes I intend to change it so that it is not locked to the framerate.
[QUOTE=daigennki;52488461]Okay, added validation for [I]curLine[/I], now looks like this: [code]if (text[curChar] == L'\n' && curLine == 1) curLine++; //Go to next line if current character is newline else textElement[curLine].text += text[curChar]; //Otherwise append next character to the string[/code] Still getting the same exception though. [editline]20th July 2017[/editline] And yes I intend to change it so that it is not locked to the framerate.[/QUOTE] I didn't see this before, but here's what's wrong: Arrays in C++ are 0 based, so you have to use [I]0[/I] and [I]1[/I] instead of [I]1[/I] and [I]2[/I] as line index. I don't know why it doesn't segfault before you advance to the next line. It probably overwrites and reads unrelated but valid memory of the current instance.
[QUOTE=Tamschi;52488476]I didn't see this before, but here's what's wrong: Arrays in C++ are 0 based, so you have to use [I]0[/I] and [I]1[/I] instead of [I]1[/I] and [I]2[/I] as line index. I don't know why it doesn't segfault before you advance to the next line.[/QUOTE] Holy shit, I am not sure how I did not realize that either. Made it start at 0 instead of one, works exactly as expected now. Thanks. Also, now that you mentioned it, how can I go about making the text speed not locked to the framerate?
[QUOTE=daigennki;52488486]Holy shit, I am not sure how I did not realize that either. Made it start at 0 instead of one, works exactly as expected now. Thanks.[/QUOTE] I completely missed it the first time around and almost didn't notice it on the second try either :v: [QUOTE]Also, now that you mentioned it, how can I go about making the text speed not locked to the framerate?[/QUOTE] I'd go with a character delay (example implementation, probably not great): [code]private: float characterTime = 0f; // Reset this when text changes. public: float characterDelay = 1f; // Is draw(...)'s delta in seconds or milliseconds?[/code][code] //Append next character to displayed string characterTime += delta; while (curChar < text.length() && characterTime >= characterDelay) { characterTime -= characterDelay; // This line together with the loop here lets you print more than one character per frame. if (text[curChar] == '\n') curLine++; //Go to next line if current character is newline else textElement[curLine].text += text[curChar]; //Otherwise append next character to the string curChar++; }[/code] Similarly to how you check for newlines, you can insert control sequences that change the delay. Most games handle it this way, I think. There's another issue with your code right now: If you only append one [I]std::wchar[/I] at a time, you can accidentally split UTF-16 surrogate pairs. It shouldn't be a problem with most western and [I]most[/I] Japanese text, but emoji, rare kanji and certain other languages will probably cause errors when a character is split. Ideally, you should advance text by whole graphemes, but that's [URL="http://www.unicode.org/reports/tr29/"]somewhat complicate[/URL][URL="https://archive.is/THXGz"]d[/URL] to say the least. If you at least use codepoints (by handling surrogate pairs correctly), certain strings (with combining characters) may still look a bit strange but won't glitch as badly since they'll always be technically valid.
[QUOTE=Tamschi;52488551]I completely missed it the first time around and almost didn't notice it on the second try either :v: I'd go with a character delay (example implementation, probably not great): [code]private: float characterTime = 0f; // Reset this when text changes. public: float characterDelay = 1f; // Is draw(...)'s delta in seconds or milliseconds?[/code][code] //Append next character to displayed string characterTime += delta; while (curChar < text.length() && characterTime >= characterDelay) { characterTime -= characterDelay; // This line together with the loop here lets you print more than one character per frame. if (text[curChar] == '\n') curLine++; //Go to next line if current character is newline else textElement[curLine].text += text[curChar]; //Otherwise append next character to the string curChar++; }[/code] Similarly to how you check for newlines, you can insert control sequences that change the delay. Most games handle it this way, I think.[/quote] Exactly what I wanted. Thank you! :happy: [quote]There's another issue with your code right now: If you only append one [I]std::wchar[/I] at a time, you can accidentally split UTF-16 surrogate pairs. It shouldn't be a problem with most western and [I]most[/I] Japanese text, but emoji, rare kanji and certain other languages will probably cause errors when a character is split. Ideally, you should advance text by whole graphemes, but that's [URL="http://www.unicode.org/reports/tr29/"]somewhat complicate[/URL][URL="https://archive.is/THXGz"]d[/URL] to say the least. If you at least use codepoints (by handling surrogate pairs correctly), certain strings (with combining characters) may still look a bit strange but won't glitch as badly since they'll always be technically valid.[/QUOTE] I do not think the font I am using supports those kinds of characters anyways, but thanks for pointing that out too, will keep it in mind.
[IMG]http://i.imgur.com/axJndS8.png[/IMG] Any suggestions to improve the design? I'm no designer and I struggle with laying pages out. I was going for an excel look.
[del]I'm having trouble reading .bmp files, I have exported 2 test bitmaps from gimp, and also 2 from mspaint and in all 4 cases the offset that the pixels should start at in the header has been wrong from where they actually start (and I can't know how much padding there is from the header)[/del] [IMG]http://i.imgur.com/tQY3YXl.png[/IMG] [del]I was talking to someone on freenode #winapi and they thought it was because the biCompression field of the bitmap header wasn't 0 but that wasn't true in all of my test exports so I don't think that's why, there just seems to be some weird padding before the pixels. I don't think it should be the color table because these aren't indexed bitmaps[/del] [editline]20th July 2017[/editline] Wait the first pixel in bmp is bottom-left not bottom-right there goes 2 days of me pointlessly thinking I had somehow missed something in the header spec.
[QUOTE=zakedodead;52489090]Wait the first pixel in bmp is bottom-left not bottom-right there goes 2 days of me pointlessly thinking I had somehow missed something in the header spec.[/QUOTE] - Unless the height is negative([I]!!![/I]&#8203;), in which case the image is stored upside down. I've been down the BMP format road trying to write a decently abstracted BMP loader/writer, but the amount of exceptions and special cases are nearly impossible to comprehend. Let me know if you need a shoulder to cry on, or a rubber duck substitute.
[QUOTE=jwhm;52489055][IMG]http://i.imgur.com/axJndS8.png[/IMG] Any suggestions to improve the design? I'm no designer and I struggle with laying pages out. I was going for an excel look.[/QUOTE] It's nice so far. Maybe using icons from Font Awesome to differentiate the fields to break up the monotony.
I'm having a little bit of a conceptual problem. I'm looking to implement CSG style brushes into my engine. So far I've hard coded it as a 3D rectangle. My issue is that I'm trying to figure out how I could auto generate UV's for arbitrary faces, such that as the size for faces increases their textures will loop. Given a scenario where the normal of a face isn't pointing straight down a specific axis, how can I determine how wide and how tall a face is so I can know how many times to loop the UV's by? [B]Edit:[/B] I've come up with a solution. By calculating a TBN matrix for each face and multiplying it by each vertex of the face, the points then naturally get transformed into tangent space, allowing me to use their x and y coordinates directly as texture coordinates for those vertices.
Anyone familiar with Game Maker engine? I could use some advice here. I am currently making my own game using Game Maker 8(Yup, a program decades old, but it's first thing I got and first thing I tried to create games on). I am currently coding protagonist's collision behavior. There's something wrong with it, however. Mako clings to walls - an unintended feature. I don't want him to cling to the wall, I want him to move up and down as usual even when he is right next to the wall. [url]https://www.4shared.com/video/tnYRJO..._to_Walls.html[/url] Sorry for putting a video like that, and not from YouTube. Can't afford YouTube right now. Anyway, here's also a code I use, partly learned from tutorials. [IMG]http://i.imgur.com/JugQbXQ.png[/IMG] [IMG]http://i.imgur.com/yd9P3aU.png[/IMG] I hope there actually are some people familiar with GameMaker, and thus, able to help me out by telling me what tweaks to do to stop Mako from clinging the walls. P. S.: I forgot to mention that the protagonist is as wide as 8 pixels, and exact calculation of collisions is disabled.
This technically counts as a web dev question since it's in Javascript but the nature of it is more a general programming question so it probably fits better here. So I have a structure which has child structures of the same type within it which can also contain their own child structures to a certain depth. What's the best way to iterate over all of these to construct something out of them? For example if I have this: [code]Parent Child Child Child Child Child Child[/code] then what's the best way to go through this? It seems like a recursive call would work best but my attempt at that screwed up somewhere along the way and I can't quite figure out where. Just at some point it starts returning the entire object itself.
Have you read about depth-first and breadth-first searches? I think the algorithms are pretty simple and they each have their trade-offs (time and memory).
[QUOTE=tschumann;52497816]Have you read about depth-first and breadth-first searches? I think the algorithms are pretty simple and they each have their trade-offs (time and memory).[/QUOTE] Do you happen to have any sort of reference I could use as a starting point for giving that a try? I think I get the most basic concept of them (depth-first would go through each child and then its child and so on until it reaches a node without a child if I'm not mistaken while breadth-first would go through each level at a time, no?) but it's a concept I've really got no experience with at all.
I learned from university lecture notes so I'm not sure of any good references on-line but yeah you're pretty much right with depth first. What's your data structure look like and what are you trying to construct?
[QUOTE=tschumann;52497973]I learned from university lecture notes so I'm not sure of any good references on-line but yeah you're pretty much right with depth first. What's your data structure look like and what are you trying to construct?[/QUOTE] My data structure is currently this: [CODE]class unistructure { constructor(name, description, type, traits, children = []) { this.name = name; this.description = description; if (typeof type === "number") { this.type = planes.mechanics.types[type]; } else { this.type = planes.mechanics.typen[type]; } this.traits = traits; this.children = children; } }[/CODE] Anything in children would be another structure of the same type and these can go up to a total of three or four levels deep. What I'm trying to construct from this is an element on a web page which shows the first structure and its various fields with the children field subsequently containing the same data for each of its children and then their children.
Maybe something like (sorry if there are bugs or whatever, I don't do much Javascript at the moment and I was in a rush and didn't have time to think through this a whole lot): [code] var elements = []; function traverse( structure, field ) { if( structure.children === undefined ) { elements.push( field ); return; } else { for( var i = 0; i < structure.children.length; i++) { traverse( structure.children[i], structure.children[i].field + field ); } } } traverse( unistructures, '' ); [/code]
Got yet another weird one with my C++ code. Trying to draw a few menus and dialogue boxes in my game: [code]DialogueBox defDBox; MenuList chooseYesNo; void drawMainMenu(float delta) { static MenuList savelist; if (savelist.w == 0 && savelist.h == 0) { savelist.w = 384; savelist.h = 192; savelist.items.resize(5); //TODO: at this point check if each save file exists savelist.items[0] = localize("save_1") + L": " + L"Save1_Name"; savelist.items[1] = localize("save_2") + L": " + L"Save2_Name"; savelist.items[2] = localize("save_3") + L": " + L"Save3_Name"; savelist.items[3] = localize("copy_save"); savelist.items[4] = localize("delete_save"); focusElement = &savelist; } int selectedSave = savelist.draw(); static InfoBox saveinfo; if (saveinfo.w == 0 && saveinfo.h == 0) { saveinfo.y = savelist.h; saveinfo.w = 320; saveinfo.h = 256; saveinfo.text = localize("empty_save"); } saveinfo.draw(); static int saveToLoad; switch (selectedSave) { case 0: case 1: case 2: defDBox.text = localize("start_save_message_a") + localize("save_" + std::to_string(selectedSave+1)) + localize("start_save_message_b"); focusElement = &defDBox; saveToLoad = selectedSave; break; case 3: break; case 4: break; } if (focusElement == &defDBox) { if (defDBox.draw(delta)) { //focusElement = &chooseYesNo; } } if (focusElement == &chooseYesNo) { defDBox.draw(delta); } }[/code] When defDBox.draw(delta) is called, I get this: [quote]Exception thrown: write access violation. _Left was nullptr. If there is a handler for this exception, the program may be safely continued.[/quote] The weird thing is, instead of declaring it outside the function, if I declare [I]defDBox[/I] as a static DialogueBox inside the function, it works as it should, no exceptions thrown. However, I want to be able to re-use that same [I]defDBox[/I] outside of that function. Any ideas as to what is happening?
Kind of hard to tell without knowing what all these classes are. However, having statics that get initialized like that feels smelly to me. An alternative would be a constructor or an initialization function. Are those other variables globals? That's also probably not a good idea.
Resubmission of a post, since again, I forgot to mention something else, but my post was already overlapped. If there are still people that are familiar with Game Maker, I could actually use their help. I am currently making my own game using Game Maker 8(Yup, a program decades old, but it's first thing I got and first thing I tried to create games on). I am currently coding protagonist's collision behavior. There's something wrong with it, however. Mako clings to walls - an unintended feature. I don't want him to cling to the wall, I want him to move up and down as usual even when he is right next to the wall. Here's a code I use, partly learned from tutorials, except for last pic. [IMG]http://i.imgur.com/JugQbXQ.png[/IMG] [IMG]http://i.imgur.com/yd9P3aU.png[/IMG] [IMG]http://i.imgur.com/f6Dt5E7.png[/IMG] I try to avoid "Jump to position" style movement, since I want Mako to move more like Mario-style. Friction and all such. If anyone wonders, the protagonist is as wide as 8 pixels and exact calculations on collision mask is disabled. The problem is, Mako stops moving vertically(heither jumps nor falls) when he contacts the walls in midair. Here's video of that problem. Sorry, can't afford YouTube right now. [url]https://www.4shared.com/video/tnYRJO..._to_Walls.html[/url] Speaking of YouTube, I've tried to find solution here, but no luck. Most of the times, it's either not a platformer or the solution is done wrong. I hope there actually are some people familiar with GameMaker, and thus, able to help me out by telling me what tweaks to do to stop Mako from clinging the walls.
[QUOTE=tschumann;52498763]Maybe something like (sorry if there are bugs or whatever, I don't do much Javascript at the moment and I was in a rush and didn't have time to think through this a whole lot): [code] var elements = []; function traverse( structure, field ) { if( structure.children === undefined ) { elements.push( field ); return; } else { for( var i = 0; i < structure.children.length; i++) { traverse( structure.children[i], structure.children[i].field + field ); } } } traverse( unistructures, '' ); [/code][/QUOTE] Unfortunately this just ends up returning an empty array. It's a fairly similar method to the last one I'd tried myself. [CODE]function uniparser(input) { let output = []; if (!Array.isArray(input)) { for (let i in input) { output[output.length] = `${i}: ${parserswitch(input, i)}`; } } else { for (let i = 0; i < input.length; i++) { output[output.length] = parserswitch(input, i); } } return output; } function parserswitch(input, i) { let output = []; switch (i) { case "children": output[output.length] = uniparser(input[i]); break; case "traits": for (let j = 0; j < input[i].length; j++) { output[output.length] = `${input[i][j].type} (${input[i][j].magnitude})`; } break; default: output[output.length] = input[i]; } output = output.join(", "); return output; }[/CODE] Though my attempt here is probably far more inefficient because I kept adding on to it trying to work out what its issues were.
[QUOTE=Loremaster;52499982]Resubmission of a post, since again, I forgot to mention something else, but my post was already overlapped. If there are still people that are familiar with Game Maker, I could actually use their help. I am currently making my own game using Game Maker 8(Yup, a program decades old, but it's first thing I got and first thing I tried to create games on). I am currently coding protagonist's collision behavior. There's something wrong with it, however. Mako clings to walls - an unintended feature. I don't want him to cling to the wall, I want him to move up and down as usual even when he is right next to the wall. Here's a code I use, partly learned from tutorials, except for last pic. [IMG]http://i.imgur.com/JugQbXQ.png[/IMG] [IMG]http://i.imgur.com/yd9P3aU.png[/IMG] [IMG]http://i.imgur.com/f6Dt5E7.png[/IMG] I try to avoid "Jump to position" style movement, since I want Mako to move more like Mario-style. Friction and all such. If anyone wonders, the protagonist is as wide as 8 pixels and exact calculations on collision mask is disabled. The problem is, Mako stops moving vertically(heither jumps nor falls) when he contacts the walls in midair. Here's video of that problem. Sorry, can't afford YouTube right now. [url]https://www.4shared.com/video/tnYRJO..._to_Walls.html[/url] Speaking of YouTube, I've tried to find solution here, but no luck. Most of the times, it's either not a platformer or the solution is done wrong. I hope there actually are some people familiar with GameMaker, and thus, able to help me out by telling me what tweaks to do to stop Mako from clinging the walls.[/QUOTE] I never used the drag and drop functions, but I assume it has to do with the first image you posted where it says "if there is a collision --> then set gravity to 0 --> set friction to .6" are what defines interaction with the walls (or anything else with collision that you add to your game) and so modifying or disabling them might be what you are trying to do.
[QUOTE=WTF Nuke;52499709]Kind of hard to tell without knowing what all these classes are. However, having statics that get initialized like that feels smelly to me. An alternative would be a constructor or an initialization function. Are those other variables globals? That's also probably not a good idea.[/QUOTE] You are right, they look disgusting without constructors now that I know what those are. Seems like using constructors might have actually fixed the problem. Thanks for pointing that out.
[QUOTE=zakedodead;52500474]I never used the drag and drop functions, but I assume it has to do with the first image you posted where it says "if there is a collision --> then set gravity to 0 --> set friction to .6" are what defines interaction with the walls (or anything else with collision that you add to your game) and so modifying or disabling them might be what you are trying to do.[/QUOTE] That's for when protagonist do this on ground, but the problem is that Mako also clings to walls [B]in midair[/B]. I don't think it has anything to do with friction.
[QUOTE=Loremaster;52501576]That's for when protagonist do this on ground, but the problem is that Mako also clings to walls [B]in midair[/B]. I don't think it has anything to do with friction.[/QUOTE] [IMG]http://i.imgur.com/yd9P3aU.png[/IMG] If I'm understanding your problem correctly, doesn't it stem from the bit in this screenshot? If your walls are made out of the same blocks as your floors then if you move into the wall while jumping it'll set your vertical speed to 0.
Hi guys! I've recently decided to dabble into more in-depth programming. I have came up with idea for a small first program I want to build for a Windows. Remember how to put a timer on a PC in order to turn it off after X amount of time, you need to go to "Run" window and write "shutdown.exe x x x x " To keep it short, I'd love to create a simple GUI for this program, where you simply pick the amount of time you want to shutdown your PC, click on the button and it does the thing for you. It will also have a button to abort the shutdown procedure. Now, where the hell do I start? I don't even know the language for this, Visual Basic or C#? C++? (i guess this one is highly unlikely, but) How would I go about passing commands onto the "Run" window? [editline]24th July 2017[/editline] Finally, as a side note, any good starting points for learning OOP? Preferably in C++.
[QUOTE=CruelAddict;52502059]Hi guys! I've recently decided to dabble into more in-depth programming. I have came up with idea for a small first program I want to build for a Windows. Remember how to put a timer on a PC in order to turn it off after X amount of time, you need to go to "Run" window and write "shutdown.exe x x x x " To keep it short, I'd love to create a simple GUI for this program, where you simply pick the amount of time you want to shutdown your PC, click on the button and it does the thing for you. It will also have a button to abort the shutdown procedure. Now, where the hell do I start? I don't even know the language for this, Visual Basic or C#? C++? (i guess this one is highly unlikely, but) How would I go about passing commands onto the "Run" window? [editline]24th July 2017[/editline] Finally, as a side note, any good starting points for learning OOP? Preferably in C++.[/QUOTE] C#. I would never recommend Visual Basic to anyone because I don't know if any serious software companies use it anymore. C++ can do the same thing, but more people are moving towards C# these days so I'd recommend C#
Sorry, you need to Log In to post a reply to this thread.