• What do you need help with? Version 1
    5,001 replies, posted
If you have no code to put in the destructor, you don't need the destructor. Just leave it out. (The only time it makes sense to explicitly write an empty destructor is when you want the class to have a virtual destructor. In that case you have to explicitly declare the destructor, and the compiler won't auto-generate a destructor if the class has one explicitly declared, so you have to implement it yourself even if it's empty.)
I need it for deleting something out of a std::list.
Then why are you asking what to put in it? It sounds like you already know what should go in it. :-)
[QUOTE=Wyzard;26417533]Then why are you asking what to put in it? It sounds like you already know what should go in it. :-)[/QUOTE] To be honest, I don't I just know why I need one. This is the code creating the errors: [code]for(std::list<cspell>::iterator i = mainch.spells.begin(); i != mainch.spells.end(); i++) if (i->move(t)) spells.erase(i); [/code]
You should read about [url=http://cb.nowan.net/blog/2004/12/30/what-will-invalidate-your-iterators/]iterator invalidation[/url]. When you remove an element from a container, any iterators referring to that element become invalid and should no longer be used — they're garbage, much like a pointer to an object that's been deleted. The specifics of what gets invalidated depends on the container type: for std::list it's just the removed element whose iterators are invalidated, but for std::vector [i]all[/i] iterators to anything in the vector become invalid when anything is added or removed. In your loop, after you call spells.erase(i), you loop around and try to do i++, but i is an invalid iterator at that point so this is undefined behavior. The erase() function returns a (valid) iterator to the next item in the container after the one that was erased, so you can rewrite your code like this: [cpp] for (std::list<cspell>::iterator i = mainch.spells.begin(); i != mainch.spells.end();) { if (i->move(t)) { i = spells.erase(i); } else { i++; } } [/cpp] Note that the i++ has been removed from the "for" line. I don't see what this has to do with destructors, though. [editline]30th November 2010[/editline] [QUOTE=bootv2;26409433]okay I made a savegame system in fstream in c++ I've fully figured out the ios::out part. but in the ios::in part how do I skip a line in the file without reading values in it(note that I'm using ios::binary in both the in and output) I used savegame << value << endl;[/QUOTE] There isn't really a notion of "lines" in binary files because the bytes that correspond to end-of-line characters (0x0a and 0x0d) can also occur in other places in the data, such as in the binary representation of numbers. You generally can't rely on them as delimiters. Binary file formats use other ways of indicating boundaries between pieces of data. One common method, that's useful when you want to be able to "skip over" parts you don't care about it, is to prefix each chunk of data with its length. To skip from one record to the next, you just read the length number and seek forward by that amount.
[QUOTE=Wyzard;26418086]You should read about [url=http://cb.nowan.net/blog/2004/12/30/what-will-invalidate-your-iterators/]iterator invalidation[/url]. When you remove an element from a container, any iterators referring to that element become invalid and should no longer be used &#8212; they're garbage, much like a pointer to an object that's been deleted. The specifics of what gets invalidated depends on the container type: for std::list it's just the removed element whose iterators are invalidated, but for std::vector [i]all[/i] iterators to anything in the vector become invalid when anything is added or removed. In your loop, after you call spells.erase(i), you loop around and try to do i++, but i is an invalid iterator at that point so this is undefined behavior. The erase() function returns a (valid) iterator to the next item in the container after the one that was erased, so you can rewrite your code like this: [cpp] for (std::list<cspell>::iterator i = mainch.spells.begin(); i != mainch.spells.end();) { if (i->move(t)) { i = spells.erase(i); } else { i++; } } [/cpp] Note that the i++ has been removed from the "for" line. I don't see what this has to do with destructors, though. [editline]30th November 2010[/editline] There isn't really a notion of "lines" in binary files because the bytes that correspond to end-of-line characters (0x0a and 0x0d) can also occur in other places in the data, such as in the binary representation of numbers. You generally can't rely on them as delimiters. Binary file formats use other ways of indicating boundaries between pieces of data. One common method, that's useful when you want to be able to "skip over" parts you don't care about it, is to prefix each chunk of data with its length. To skip from one record to the next, you just read the length number and seek forward by that amount.[/QUOTE] Are you Wyzard? Thanks a lot man.
[QUOTE=WTF Nuke;26418858]Are you Wyzard?[/QUOTE] Last time I checked, yes.
Snip, read the comment wrong and it was somewhat rude
I have this in the OnThink function on my panel (called every frame) [code] for ( int i = 1; i < MAX_INVENTORYITEMS; i++ ) { if ( player ) { C_BaseCombatWeapon * weapon = player->GetWeapon( i ); //Item_t * item = GetItemDef()->GetItemOfIndex(i); if ( weapon ) { Q_snprintf(buffer, sizeof(buffer), "image%i", i); itemButton = new ImageButton( this, buffer, "inventory/null", "inventory/nullover", "inventory/nullclick", "deleteme" ); itemButton->SetSize(64, 64); itemButton->SetProportional( true ); //Create Label Q_snprintf(buffer, sizeof(buffer), "%s", weapon->GetWpnData().szPrintName); Label* label = new Label( this, buffer, buffer ); label->SetText(buffer); label->SetProportional( true ); controlGrid->AddItem( itemButton, label ); } } }[/code] It works, but since it's constantly being called even when no changes are made it just keeps adding stuff forever. How can I set it to only call once (it's probably a better idea to call it somewhere else actually, like when the inventory button is pressed)
I have 2 problems: 1. For my minecraft server, I am doing it nearly completely and am using the socket and struct dlls. I can have clients connect, I accept the connection, I get back a client socket, aaaand... I don't receive anything from it. ever. 2. I have a personal lua development program, made in C#, with some bit of a hacky filesystem thrown in for fun. Recently, It started just printing "Object reference not set to an instance of an object", and nothing else. I know it's not part of the lua, so it must be the C#, yet VSC doesn't even throw an error. (If it's needed, I can post the code.) I really don't know what to do for either of these, I've been at a lack of an answer despite my best efforts, and have become quite bored. Does anyone know what I should do?
1: [url]http://mc.kev009.com/wiki/Protocol#Handshake_.280x02.29[/url] or [url]http://www.minecraftwiki.net/wiki/Classic_Server_Protocol#Server_.E2.86.92_Client_packets[/url] 2: So, if the error comes from neither Lua nor C#, where does it come from? Where did it pop up?
I'm currently making a program in assembly which stores 4 numbers in an array, adds them together and then divides the sum by 4 in order to get an average. I'm having trouble with the division bit and printing the result. Here is the loop i'm using to add the 4 numbers which have been input by the user: [CODE] mov ecx,4 // size of the array is saved in the counter mov eax,0 // eax will be used to hold the sum, initialise to 0 mov ebx,0 // ebx acts as index of the array Loop1: add eax,myarray[ebx] //read an element of the array at the address //myarray+ebx add ebx,4 //int occupies 4 bytes (32 bits), //so to read next element increase ebx by 4 loop Loop1 // the end of the loop [/CODE] For division i'm using the SAR command as if I shift the result 2 places to the right it will be the same as dividing by 4. [CODE] sar eax, 2 push eax lea eax,format (format is "%d", declared in C++) push eax call printf ; [/CODE] However this prints out a weird numbers, like if all of the 4 integers are 2 then the result will be 434562790. Can anyone tell me what's wrong or what I am doing wrong?
I'm trying to make simple physics, but now, the collision is sometimes working, sometimes not. A box always stops somewhere, and when other boxes collides on this box, these boxes stopping failing, other boxes still failing... What's wrong with this code? Enter - adds boxes Delete - removes boxes Escape - escape [img]http://img689.imageshack.us/img689/3317/boxnormaltpdn.png[/img] [code] using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage; namespace Dynamicaller { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; public Random rand = new Random(); public static List<Sprite> sprlist = new List<Sprite>(); public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); //for(int i = 0; i < 15; i++) // sprlist.Add(new Sprite(Texture2D.FromFile(GraphicsDevice, @"Data\box_norm_alt_pdn.png"), new Vector2(rand.Next(0, 800), rand.Next(1, 600)))); } protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } protected override void Update(GameTime gameTime) { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) this.Exit(); if (Keyboard.GetState().IsKeyDown(Keys.Enter)) sprlist.Add(new Sprite(Texture2D.FromFile(GraphicsDevice, @"Data\box_norm_alt_pdn.png"), new Vector2(rand.Next(0, 800 - 48), rand.Next(1, 600 - 48)))); if (Keyboard.GetState().IsKeyDown(Keys.Delete)) if(sprlist.Count != 0) sprlist.RemoveAt(sprlist.Count - 1); foreach (Sprite spr in sprlist) spr.Update(gameTime); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); base.Draw(gameTime); spriteBatch.Begin(); foreach (Sprite spr in sprlist) { spriteBatch.Draw(spr.texture, spr.position, spr.color); } spriteBatch.End(); } } } [/code] [code] using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace Dynamicaller { public class Sprite { public Texture2D texture; public Vector2 position; public Color color; public bool IsFailing = true; public Rectangle colRect; public int Width { get { return texture.Width; } } public int Height { get { return texture.Height; } } public Sprite(Texture2D tex, Vector2 pos) { texture = tex; position = pos; color = Color.White; colRect = new Rectangle((int)position.X, (int)position.Y, Width, Height); } public Sprite(Texture2D tex, Vector2 pos,Color col) { texture = tex; position = pos; color = col; colRect = new Rectangle((int)position.X, (int)position.Y, Width, Height); } public void Update(GameTime gametime) { if(position.Y != 600 - 48 && position.Y <= 600 - 48) if (IsFailing) position.Y++; colRect.X = (int)position.X; colRect.Y = (int)position.Y; colRect.Width = Width; colRect.Height = Height; foreach (Sprite spr in Game1.sprlist) { if (colRect.Intersects(spr.colRect)) IsFailing = false; else IsFailing = true; } } } } [/code]
Is there a way to get anti-alias in SFML?
[QUOTE=TerabyteS;26429496]Is there a way to get anti-alias in SFML?[/QUOTE] Doesn't SFML have it on by default?
[QUOTE=TerabyteS;26429496]Is there a way to get anti-alias in SFML?[/QUOTE] sf::ContexSettings Settings; Settings.AntiAliasing = x; sf::RenderWindow Window( sf::VideoMode( 800, 600, 32U ), "Caption", sf::Style::Close, Settings ); Where 'x' is the level of AA you want.
[QUOTE=NorthernGate;26430504]sf::ContexSettings Settings; Settings.AntiAliasing = x; sf::RenderWindow Window( sf::VideoMode( 800, 600, 32U ), "Caption", sf::Style::Close, Settings ); Where 'x' is the level of AA you want.[/QUOTE] Its going to sound stupid but: what levels of AA can you have? i only ever see 2, 4, 8, 16 and on some games 32
[QUOTE=Richy19;26431322]Its going to sound stupid but: what levels of AA can you have? i only ever see 2, 4, 8, 16 and on some games 32[/QUOTE] Not positive, I believe the amount is the amount of passes made over the screen. So try experimenting.
[QUOTE=Richy19;26431322]Its going to sound stupid but: what levels of AA can you have? i only ever see 2, 4, 8, 16 and on some games 32[/QUOTE] Anything. It's the scale-factor. Anti-aliasing works by rendering the image on x-times the actual size and then down-scaling it, thus aliased edges become blurred.
You won't see much of a difference after 8x and no difference at all after 16x anyways.
I am trying to make a Taskdialog, I am running windows 7 and this is the code I am using... [csharp] #include <stdio.h> #include <Windows.h> #include <CommCtrl.h> int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { int result = 0; TaskDialog(NULL, NULL, L"Press OK", L"Press OK", L"This is another Test", NULL, TD_SHIELD_ICON, &result); return 0; } [/csharp] I get a error when i start the program that says The ordinal 344 could not be found in the dynamic link library COMCTL32.dll
[QUOTE=ZeekyHBomb;26431887]Anything. It's the scale-factor. Anti-aliasing works by rendering the image on x-times the actual size and then down-scaling it, thus aliased edges become blurred.[/QUOTE] Depends on the type of AA. You've just described supersampling, which AFAIK is rarely used because of performance considerations. MSAA is what most people think of when they say AA, and it goes up to 4x or 8x I think. 8x(sometimes), 16x, and 32x are (nVidia anyways, no idea what AMD does) CSAA, which IIRC is 4x or 8x MSAA with additional edge-based processing and little loss in performance. But yeah after 8 there's not much of a difference.
[QUOTE=Gibo990;26426114]I'm currently making a program in assembly which stores 4 numbers in an array, adds them together and then divides the sum by 4 in order to get an average. I'm having trouble with the division bit and printing the result. Here is the loop i'm using to add the 4 numbers which have been input by the user: However this prints out a weird numbers, like if all of the 4 integers are 2 then the result will be 434562790. Can anyone tell me what's wrong or what I am doing wrong?[/QUOTE] How are you getting the input? Are the numbers coming in as signed or unsigned?
[QUOTE=BMCHa;26440423]Depends on the type of AA. You've just described supersampling, which AFAIK is rarely used because of performance considerations. MSAA is what most people think of when they say AA, and it goes up to 4x or 8x I think. 8x(sometimes), 16x, and 32x are (nVidia anyways, no idea what AMD does) CSAA, which IIRC is 4x or 8x MSAA with additional edge-based processing and little loss in performance. But yeah after 8 there's not much of a difference.[/QUOTE] The different between SSAA and MSAA is that MSAA does not scale a bunch of auxiliary buffers. And CSAA is, I think, just a special down-scaling algorithm, which seems to provide a better looking picture that SSAA/MSAA on the same scaling factor.
[QUOTE=Gibo990;26426114]For division i'm using the SAR command as if I shift the result 2 places to the right it will be the same as dividing by 4. [/quote] SAR is an arithmetic shift and does some funky stuff regarding the sign bit which I don't understand (never really looked into it). You might have better luck with SHR
I looked up SAR in Intel's reference manual and if I understand correctly, what it does is analogous to [url=http://en.wikipedia.org/wiki/Sign_extension]sign extension[/url]: the new bits added on the left of the number are copies of the original leftmost bit, so that negative numbers stay negative. With SHR, the new bits are always zero. For positive numbers, both instructions should produce the same results. Gibo990, are you sure the shifting is the problem? Maybe the numbers aren't being added correctly. I'd recommend stepping through the instructions in a debugger to see what's going on.
Cheers for the suggestions guys, I managed to get it working I wasn't summing the numbers correctly. Works perfect now.
I compiled my program with MinGW. Runs on my pc fine. I try running it on dad's pc, I get [B]"libgcc_s_dw2-1.dll not found"[/B]. Tried looking for it on my pc, not found. Is there a way to tell the complier to make the executable not require that, or to actually find the dll file?
[QUOTE=TerabyteS;26453658]I compiled my program with MinGW. Runs on my pc fine. I try running it on dad's pc, I get [B]"libgcc_s_dw2-1.dll not found"[/B]. Tried looking for it on my pc, not found. Is there a way to tell the complier to make the executable not require that, or to actually find the dll file?[/QUOTE] [quote]Dynamic linking with libgcc_s_dw2-1.dll is necessary to throw exceptions between different modules, such as between two DLLs or a DLL and an EXE. Consequently, it is the default for all languages other than C. To disable this dynamic linking, use -static-libgcc.[/quote] [url]http://sourceforge.net/project/shownotes.php?release_id=691876[/url]
how hard would it be to make the simplest online multiplayer game ever. Just something like 2 moving dots or something like that ???
Sorry, you need to Log In to post a reply to this thread.