• What do you need help with? V4 (January 2012)
    966 replies, posted
  • Is there a way to force visual C++ to include macro's in a static library. For example: lib.h: [code] void doStuff(); [/code] lib.cpp: [code] #include "lib.h" #ifdef useint void doStuff() {int bloop;} #else void doStuff() {bool bloop;} #endif [/code] App.cpp: [code] #define useint #include "lib.h" int main() {doStuff()} [/code] I say this because I am building an engine and I would like to define these macros per-build. [editline]5th February 2012[/editline] [QUOTE=DestWa;34539883]XNA or Pygame? I already know some xna so I guess this is a stupid question but what do you guys prefer? (didn't want to make a thread) Also is making a simple text based game ( like the good 'ol roguelikes or DwarfFortress or something ) possible with either or should I do it in java or something?[/QUOTE] IF you want to make a text based game you want to just make a console application like a C++ console application using cout and cin and such.
  • I'm sort of tired, so I must be making a really stupid mistake, but here it goes. [code] unsigned char m1[]="abc"; unsigned char m2[64]; for(int i=0; i<64; i++){ m2[i]='a'; } printf("%s\n",m1); printf("%s\n",m2); [/code] Output: [code]abc aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaÌÌÌÌÌÌÌÌabc[/code] What's going on with the second line?
  • You're missing the null terminator. ( \0 ) The second line is actually 75 characters long because of that.
  • [QUOTE=flayne;34566789]Is there a way to force visual C++ to include macro's in a static library. For example: lib.h: [code] void doStuff(); [/code] lib.cpp: [code] #include "lib.h" #ifdef useint void doStuff() {int bloop;} #else void doStuff() {bool bloop;} #endif [/code] App.cpp: [code] #define useint #include "lib.h" int main() {doStuff()} [/code] I say this because I am building an engine and I would like to define these macros per-build.[/QUOTE] that's not how it works, it goes by whatever macro is defined when lib.cpp is compiled. If you [i]really[/i] want to do what you're trying, do something like this: [b]lib.hpp[/b]: [cpp] _doStuffInt(); _doStuffBool(); static void doStuff() { #ifdef useint _doStuffInt(); #else _doStuffBool(); #endif } [/cpp] [b]lib.cpp[/b]: [cpp] void _doStuffInt() {int bloop;} void _doStuffBool() {bool bloop;} [/cpp] (also, please don't use .h for C++ header files)
  • [QUOTE=ief014;34568936]You're missing the null terminator. ( \0 ) The second line is actually 75 characters long because of that.[/QUOTE] Thank goodness for Facepunch help, you can always count on someone to get a response to you quickly. Sometimes after working on a bunch of code you just need a fresh pair of eyes. You're absolutely correct, I can't believe I made such a mistake with c-style strings. The example above is a simplified version of what I'm actually dealing with, although I did narrow down the problem to that piece of code. In reality both m1 and m2 are hashes of data that might have multiple null-terminators in them, and the loop is a transformation on one of the hashes.
  • [QUOTE=Sir Whoopsalot;34570470]In Java, how would one go about targeting the surface of a JFrame?[/QUOTE] what do you mean by targeting and what do you mean by surface? You could replace the content frame with your own component and override drawComponent if that's what youre trying to do
  • I've been working with SharpDevelop for C#, but I recently got another monitor, and although you can use vertical tabs to see more of the code/ other windows, is there any way to bind or link the scrollbars of the different windows so that when I scroll it in one it can scroll it as a whole? If not in SharpDevelop, are there any IDE's that might?
  • I have a problem where the same free space is assigned to different structures in MarsMiner's saving system. Can you please have a look at [URL="https://github.com/Tamschi/MarsMiner/blob/reusable-space-attempt/MarsMiner.Saving/Util/IntRangeList.cs"]https://github.com/Tamschi/MarsMiner/blob/reusable-space-attempt/MarsMiner.Saving/Util/IntRangeList.cs[/URL] and tell me whether the conditions are correct? The IntRangeList is supposed to store non-overlapping number ranges (inclusive start, exclusive end). [b]Edit:[/b] Fixed it. One missing line. :suicide:
  • Ok this is really bugging me! [code] 1 ItemNumber int(11) 2 ItemName varchar(100) latin1_swedish_ci 3 Price double 4 AvailableQuantity int(11) 5 Updated_Dt datetime [/code] [code] private void Form1_Load(object sender, EventArgs e) { //Initialize mysql connection connection = new MySqlConnection(ConnectionString); //Get all items in datatable DTItems = GetAllItems(); //Fill grid with items dataGridView1.DataSource = DTItems; } //Get all items from database into datatable DataTable GetAllItems() { try { //prepare query to get all records from items table string query = "select * from items"; //prepare adapter to run query adapter = new MySqlDataAdapter(query, connection); DataSet DS = new DataSet(); //get query results in dataset adapter.Fill(DS); [/code] It shows the data that is on the Database fine [code] // Set the INSERT command and parameter. adapter.InsertCommand = new MySqlCommand( "INSERT INTO items VALUES (@ItemNumber,@ItemName,@Price,@AvailableQuantity,NOW());", connection); adapter.InsertCommand.Parameters.Add("@ItemNumber", MySqlDbType.Int16, 4, "1"); adapter.InsertCommand.Parameters.Add("@ItemName", MySqlDbType.VarChar, 100, "ItemName"); adapter.InsertCommand.Parameters.Add("@Price", MySqlDbType.Decimal, 10, "Price"); adapter.InsertCommand.Parameters.Add("@AvailableQuantity", MySqlDbType.Int16, 11, "AvailableQuantity"); adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None; [/code] I followed a website that showed how to use Datagridview and MySQL , but when I try to insert anything using their code I get this. "Column 'ItemNumber' cannot be null" [editline]7th February 2012[/editline] Ok this is really bugging me! [code] // Set the INSERT command and parameter. adapter.InsertCommand = new MySqlCommand( "INSERT INTO items VALUES (@ItemNumber,@ItemName,@Price,@AvailableQuantity,NOW());", connection); adapter.InsertCommand.Parameters.Add("@ItemNumber", MySqlDbType.Int16, 4, "1"); adapter.InsertCommand.Parameters.Add("@ItemName", MySqlDbType.VarChar, 100, "ItemName"); adapter.InsertCommand.Parameters.Add("@Price", MySqlDbType.Decimal, 10, "Price"); adapter.InsertCommand.Parameters.Add("@AvailableQuantity", MySqlDbType.Int16, 11, "AvailableQuantity"); adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None; [/code] I followed a website that showed how to use Datagridview and MySQL , but when I try to insert anything using their code I get this. "Column 'ItemNumber' cannot be null" I don't know if this adds anything but I just dragged a datagriview1 onto the form, didn't modify it in anyway.
  • Style question for you guys (Keep in mind i'm coding in c#) How do you capitalize fields, properties, methods and parameters? The style I've been using it to use camelCase for private fields and parameters. Public properties and methods are PascalCase. Also, typically when does one add a "_" before a field (or is it method?) I've seen that before as well.
  • [QUOTE=DoctorSalt;34596214]Style question for you guys (Keep in mind i'm coding in c#) How do you capitalize fields, properties, methods and parameters? The style I've been using it to use camelCase for private fields and parameters. Public properties and methods are PascalCase. Also, typically when does one add a "_" before a field (or is it method?) I've seen that before as well.[/QUOTE] I use ReSharperCase. [img]http://puu.sh/g5G0[/img]
  • SFML question here: I'm making a textbox for my game. Basically what I'm doing is drawing the box, and then the text on top. However there's a bit of an issue: [img]http://i.imgur.com/TJPVA.png[/img] As you can see, since I'm just drawing text, it just keeps going even outside. Is there a way to perform something similar to sf::Sprite::SetSubRect() but for sf::Text (efficiently?)
  • I'm pretty sure you have to use OpenGL with SFML to clip in SFML(but I haven't used sfml much, so don't quote me on that) ----- I'm making a GUI system. I have a base class, well, kind of expected, a "Panel". All other panel types derive from this, such as the button. Now for my problem. I'm implementing a parent/children system. I have that idea planned out but have no clue on how to pass input events. They have functions such as onKeyPress and onMouseDrag but I don't know how to check for the panels under the mouse by traversing the panel tree. --- In gist: How do I pass events down to the proper element when all I have is a panel tree?
  • [QUOTE=marcin1337;34588880]Ok this is really bugging me! [code] 1 ItemNumber int(11) 2 ItemName varchar(100) latin1_swedish_ci 3 Price double 4 AvailableQuantity int(11) 5 Updated_Dt datetime [/code] [code] private void Form1_Load(object sender, EventArgs e) { //Initialize mysql connection connection = new MySqlConnection(ConnectionString); //Get all items in datatable DTItems = GetAllItems(); //Fill grid with items dataGridView1.DataSource = DTItems; } //Get all items from database into datatable DataTable GetAllItems() { try { //prepare query to get all records from items table string query = "select * from items"; //prepare adapter to run query adapter = new MySqlDataAdapter(query, connection); DataSet DS = new DataSet(); //get query results in dataset adapter.Fill(DS); [/code] It shows the data that is on the Database fine [code] // Set the INSERT command and parameter. adapter.InsertCommand = new MySqlCommand( "INSERT INTO items VALUES (@ItemNumber,@ItemName,@Price,@AvailableQuantity,NOW());", connection); adapter.InsertCommand.Parameters.Add("@ItemNumber", MySqlDbType.Int16, 4, "1"); adapter.InsertCommand.Parameters.Add("@ItemName", MySqlDbType.VarChar, 100, "ItemName"); adapter.InsertCommand.Parameters.Add("@Price", MySqlDbType.Decimal, 10, "Price"); adapter.InsertCommand.Parameters.Add("@AvailableQuantity", MySqlDbType.Int16, 11, "AvailableQuantity"); adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None; [/code] I followed a website that showed how to use Datagridview and MySQL , but when I try to insert anything using their code I get this. "Column 'ItemNumber' cannot be null" [editline]7th February 2012[/editline] Ok this is really bugging me! [code] // Set the INSERT command and parameter. adapter.InsertCommand = new MySqlCommand( "INSERT INTO items VALUES (@ItemNumber,@ItemName,@Price,@AvailableQuantity,NOW());", connection); adapter.InsertCommand.Parameters.Add("@ItemNumber", MySqlDbType.Int16, 4, "1"); adapter.InsertCommand.Parameters.Add("@ItemName", MySqlDbType.VarChar, 100, "ItemName"); adapter.InsertCommand.Parameters.Add("@Price", MySqlDbType.Decimal, 10, "Price"); adapter.InsertCommand.Parameters.Add("@AvailableQuantity", MySqlDbType.Int16, 11, "AvailableQuantity"); adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None; [/code] I followed a website that showed how to use Datagridview and MySQL , but when I try to insert anything using their code I get this. "Column 'ItemNumber' cannot be null" I don't know if this adds anything but I just dragged a datagriview1 onto the form, didn't modify it in anyway.[/QUOTE] oh wow that website is old. turns out all it takes now is this [code] myMySQLCommandBuilder = new MySqlCommandBuilder(adapter); adapter.UpdateCommand = myMySQLCommandBuilder.GetUpdateCommand(); adapter.DeleteCommand = myMySQLCommandBuilder.GetDeleteCommand(); adapter.InsertCommand = myMySQLCommandBuilder.GetInsertCommand(); [/code]
  • [QUOTE=ief014;34598273]SFML question here: I'm making a textbox for my game. Basically what I'm doing is drawing the box, and then the text on top. However there's a bit of an issue: [img]http://i.imgur.com/TJPVA.png[/img] As you can see, since I'm just drawing text, it just keeps going even outside. Is there a way to perform something similar to sf::Sprite::SetSubRect() but for sf::Text (efficiently?)[/QUOTE] A hacky way to do it would be to render the text into sf::RenderTexture and then render that onto you sf::RenderWindow.
  • Literally banging my head on a wall. Stuck at event handling in c#, its my first time creating my own events in c# defined my event using [code] public delegate void NetReceivedHandler(object sender, EventArgs e, string data); public event NetReceivedHandler NetRec; [/code] and [code] public void ListenOnPort() { ... NetRec(this, EventArgs.Empty, cData); } [/code] But when I define the new eventhandler, it just won't execute the events. [code] public void init() { cNet net = new cNet() Thread async = new Thread(delegate() { net.StartListen( "127.0.0.1", port ); } ); async.Start(); net.NetRec += new cNet.NetReceivedHandler( net_NetRec ); } private void net_NetRec( object sender, EventArgs e, string data ) { Console.WriteLine( "Data: " + data ); } [/code] I have no idea what I'm doing.
  • [QUOTE=Map in a box;34598651]I'm pretty sure you have to use OpenGL with SFML to clip in SFML(but I haven't used sfml much, so don't quote me on that) ----- I'm making a GUI system. I have a base class, well, kind of expected, a "Panel". All other panel types derive from this, such as the button. Now for my problem. I'm implementing a parent/children system. I have that idea planned out but have no clue on how to pass input events. They have functions such as onKeyPress and onMouseDrag but I don't know how to check for the panels under the mouse by traversing the panel tree. --- In gist: How do I pass events down to the proper element when all I have is a panel tree?[/QUOTE] I'm assuming a panel tree is a tree of everything in the UI, in no particular order of importance, besides what is a parent of what. I traditionally have a panel list (doubly linked lists work great for this), where the front-most panel is always at the start of the list. This makes rendering extremely easy (just render everything on the list, in order, starting at the back) Each panel can be its own tree, but the main panels (the movable and resizeable windows) are not part of any tree. Once you have a list, sending events is also trivial. Construct a single event object for whatever's happening (I like to separate keyboard and mouse events, though,) and just send it to every panel on the list, in order. When an event 'hits' a panel (it happens within a panel) just set a variable in it to true and continue onward. It's crucial that the event goes to every panel, so that buttons and scrollbars can be released even if the panel is blocked by something. However, when a panel sees that an event has already hit a panel, it will not let any buttons be pressed, etc. Oh, and what's nice about this system is that when a panel is given focus, just remove it from the list and insert it at the start. Simplicity. This is probably more than you need.
  • Need help with some basic thinking in Java, I've got a working program but I feel that the structure is wrong. You can give the program a zip file, it will extract it and then delete all empty files and all subfolders that have empty files. So basically when it's unzipped there can be X amount of folders, and those folders can have X amount of folders (and it's likely that those folders also have subfolders, this can go on). The application needs to check each subfolder until there are no more folders, delete all empty files and if the folder is empty, delete the folder aswell. what would be a good way to implement this? A method that checks the mainfolder, and if there are directories in that folder, send it to another method that will clean the folder and check for more subfolders? The main problem is how I can check all folders without knowing the amounts of folders and subfolders.
  • [QUOTE=Cuel;34603694]Need help with some basic thinking in Java, I've got a working program but I feel that the structure is wrong. You can give the program a zip file, it will extract it and then delete all empty files and all subfolders that have empty files. So basically when it's unzipped there can be X amount of folders, and those folders can have X amount of folders (and it's likely that those folders also have subfolders, this can go on). The application needs to check each subfolder until there are no more folders, delete all empty files and if the folder is empty, delete the folder aswell. what would be a good way to implement this? A method that checks the mainfolder, and if there are directories in that folder, send it to another method that will clean the folder and check for more subfolders? The main problem is how I can check all folders without knowing the amounts of folders and subfolders.[/QUOTE] Recursion.
  • Thanks bby. [editline]8th February 2012[/editline] [url]http://pastebin.com/Kg7FNP5S[/url] good/bad? [del]What would be a good way to delete the folders if they are empty after deleting the files?[/del] - solved, added [code] if (file.isDirectory() && file != this.getDefaultDirectory()) { File[] itemsInFolder = file.listFiles(); System.out.println(itemsInFolder.length); if (itemsInFolder.length == 0){ file.delete(); } }[/code] at the bottom. anything else for error handling etc?
  • [QUOTE=kaukassus;34603362] ... [/QUOTE] I just did something similar last night and this is what I did.. [lua] //Define event in your class public delegate void Connect(object sender, EventArgs args); public event Connect OnConnect; void CallEvent() { if(this.OnConnect) this.OnConnect(this, Eventargs.Empty); } [/lua]
  • [url='http://www.facepunch.com/threads/1162206']Need help creating flags on sounds and creating them without header.[/url]
  • I need to write a simple program (because I don't know of one that exists) that allows me to create a tree of objects. >node1 >>sub node1 >>>subsub node1 >>>subsub node2 >>>subsub node3 >>sub node2 >>sub node3 >>sub node4 >node2 I was thinking of writing it in visual basic (which I have forgotten) but perhaps there is something better to use. I'd go about HTML5 but I'm not sure how much data can be stored from a browser. I need this to write out ideas for my story. Superficial scope nodes are for general events that I need to detail later with deeper scope nodes. OH .... Silver Light?
  • Working with WebGL using JavaScript and I've run into the weirdest error ever. I have this part: [code] flatShader.VertexPositionAttribute = gl.getAttribLocation( flatShader, "v3VertexPosition" ); gl.enableVertexAttribArray( flatShader.VertexPositionAttribute ); [/code] This works, no problems at all and the shader is used to draw some lines etc... However: [code] textureShader.VertexPositionAttribute = gl.getAttribLocation( textureShader, "a_v3VertexPosition" ); gl.enableVertexAttribArray( textureShader.VertexPositionAttribute ); [/code] The next piece of code only works if I comment out the gl.enableVertexAttribArray line, otherwise an error 1282 ( INVALID_OPERATION ) occurs. [code] gl.useProgram( flatShader ); gl.bindBuffer( gl.ARRAY_BUFFER, buffer ); gl.vertexAttribPointer( flatShader.VertexPositionAttribute, 3, gl.FLOAT, false, 0, 0 ); gl.uniformMatrix4fv( flatShader.mvpMatrixUniform, false, mvpMatrix ); gl.drawArrays( gl.LINES, 0, 2 ); gl.bindBuffer( gl.ARRAY_BUFFER, null ); gl.useProgram( null ); [/code] More specifically, gl.drawArrays errors out with that error. HOWEVER, the following does not generate the same error: [code] textureShader.TextureCoordAttribute = gl.getAttribLocation( textureShader, "a_v2TextureCoord" ); gl.enableVertexAttribArray( textureShader.TextureCoordAttribute ); [/code] So what the fuck is wrong with the VertexPosition variable!? I have checked, doublechecked and rechecked every single line and there is not a single mistype to spot. And it works as soon as I comment out that line. If I add a deliberate type error in there, such as: [code] textureShader.VertexPositionAttribute = gl.getAttribLocation( textureShader, "a_v3VertexPosition" ); gl.enableVertexAttribArray( textureShader.NOSUCHVARIABLE ) [/code] It keeps on going happily and enableVertex errors out with a INVALID_VALUE instead, however the lines are drawn. Why the fuck does that one line make glDrawArrays error out, when the next glEnableVertexAttribArray does not!? [B]EDIT[/B] Figured out what was wrong. I was enabling the vertexarrays too early and unlike OpenGL, WebGL will error out on glDrawArrays / glDrawElements calls if a vertexarray is enabled on a buffer that is not populated. However after I fixed this, I still haven't been able to get my textured quad working yet... Would anybody care taking a look at my code and see if they can spot any issues that I might have missed? [url]http://dl.dropbox.com/u/40398697/WebGLProject/WebGLProject.rar[/url] Any help is appreciated. :)
  • Could anybody take a look at this : [url]http://gamedev.stackexchange.com/questions/23549/trace-with-2d-terrain[/url]
  • @capsup: Just out of curiosity, does it work if you replace gl.drawArrays with gl.drawElements, with an index buffer containing just "1, 2, 3, 4, 5, ..., n-1, n"?
  • [QUOTE=quincy18;34607733]Could anybody take a look at this : [url]http://gamedev.stackexchange.com/questions/23549/trace-with-2d-terrain[/url][/QUOTE] If you are seeing if a line intersects with another line, I'd use this article: [url]http://paulbourke.net/geometry/lineline2d/[/url]
  • [QUOTE=sim642;34602825]A hacky way to do it would be to render the text into sf::RenderTexture and then render that onto you sf::RenderWindow.[/QUOTE] That's what I was hoping to not do, but it seems like my only option.