• What do you need help with? Version 5
    5,752 replies, posted
How do I disable font smoothing in LÖVE?
I'm making my events.cpp file now, but I get linker errors when I use it. events.cpp [php] // Events.cpp #ifndef _EVENTS #define _EVENTS class Hook{ public: void Func( ); Hook( ){ }; }; class Event{ private: Hook* HookedEvents[255]; int AMT; public: Event( ){ AMT = 0; } ~Event( ){ } void AddHook( Hook* MyHook ){ AMT = AMT + 1; HookedEvents[ AMT ] = MyHook; } void Call( ){ int a = 1; for ( a = 1; a <= AMT; a++){ Hook* CurrentHook = HookedEvents[ a ]; CurrentHook->Func(); } } }; #endif [/php] Use: [php] // ... Event* OnDraw = new Event; // ... in a function OnDraw->Call(); // ... class MyDrawHook : public Hook { public: void Func(){ cout << "win"; } }; // In a function: MyDrawHook* MyDrawHook2 = new MyDrawHook; OnDraw->AddHook( reinterpret_cast<Hook*>(MyDrawHook2) ); [/php] any ideas? [Code] 1>Main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Hook::Func(void)" (?Func@Hook@@QAEXXZ)[/code]
[QUOTE=supersnail11;34976063]How do I disable font smoothing in LÖVE?[/QUOTE] You should be able to draw the text to a buffer and then nearest neighbour scale it up or down as required. I don't think you can disable it otherwise unless you use a bitmap font.
[QUOTE=Swebonny;34972962]I checked the map reference, and it stated that the ".find" executes in logarithmic time, [del]while your second code seems to do things in constant time. So the last one should be faster.[/del] [url]http://www.facepunch.com/threads/1167392?p=34974180&viewfull=1#post34974180[/url][/QUOTE] I went ahead and checked it, turns out direct "if else" takes twice as long. Then I saw the update to your post. I thought switch statements were all optimized and fast and shit, but it makes a lot of sense to keep the function in the map, and just doing something like "return it->second". Thanks dudebros.
[QUOTE=Eudoxia;34976723]I went ahead and checked it, turns out direct "if else" takes twice as long. Then I saw the update to your post. I thought switch statements were all optimized and fast and shit, but it makes a lot of sense to keep the function in the map, and just doing something like "return it->second". Thanks dudebros.[/QUOTE] Thank Wyzard :v:
I wrote a simple C function to uppercase a string without altering the original. It works fine, except there's a weird bug that causes the 9th character to always change to the next letter in the alphabet (so [b]r[/b] changes to [b]s[/b] and [b]a[/b] to [b]b[/b], etc.) [cpp]char* strtoupper(char* str) { char* strup = ""; int i; size_t i_max = sizeof(str) * sizeof(char*); for (i = 0; i < i_max; i++) { strup[i] = toupper(str[i]); } return strup; }[/cpp] [cpp]printf("%s", strtoupper("Character Stats")); // outputs 'CHARACTES STATS'[/cpp] Any ideas on what's causing this?
I've recently been working on a sort of "Game Engine" in XNA and I've got entities down etc, but I'm not sure on how to store/load/display maps, I've been trying all day and all the examples like to use height maps which I have come to hate. My question is basically what method should I look in to other than height maps for maps in an XNA project.
[QUOTE=aerochug;34977438]I wrote a simple C function to uppercase a string without altering the original. It works fine, except there's a weird bug that causes the 9th character to always change to the next letter in the alphabet (so [b]r[/b] changes to [b]s[/b] and [b]a[/b] to [b]b[/b], etc.) [cpp]char* strtoupper(char* str) { char* strup = ""; int i; size_t i_max = sizeof(str) * sizeof(char*); for (i = 0; i < i_max; i++) { strup[i] = toupper(str[i]); } return strup; }[/cpp] [cpp]printf("%s", strtoupper("Character Stats")); // outputs 'CHARACTES STATS'[/cpp] Any ideas on what's causing this?[/QUOTE] Maybe you could try using strlen to get the size of your string.
[QUOTE=evil-tedoz;34978244]Maybe you could try using strlen to get the size of your string.[/QUOTE] That works, but the output doesn't change :downs:
[QUOTE=aerochug;34977438]I wrote a simple C function to uppercase a string without altering the original. It works fine, except there's a weird bug that causes the 9th character to always change to the next letter in the alphabet (so [b]r[/b] changes to [b]s[/b] and [b]a[/b] to [b]b[/b], etc.) [cpp]char* strtoupper(char* str) { char* strup = ""; int i; size_t i_max = sizeof(str) * sizeof(char*); for (i = 0; i < i_max; i++) { strup[i] = toupper(str[i]); } return strup; }[/cpp] [cpp]printf("%s", strtoupper("Character Stats")); // outputs 'CHARACTES STATS'[/cpp] Any ideas on what's causing this?[/QUOTE] You never allocate memory for strup. So you are probably getting some undefined behavior from writing to 'unallocated' memory.
-found a work around-
[QUOTE=aerochug;34977438]I wrote a simple C function to uppercase a string without altering the original. It works fine, except there's a weird bug that causes the 9th character to always change to the next letter in the alphabet (so [b]r[/b] changes to [b]s[/b] and [b]a[/b] to [b]b[/b], etc.) [cpp]char* strtoupper(char* str) { char* strup = ""; int i; size_t i_max = sizeof(str) * sizeof(char*); for (i = 0; i < i_max; i++) { strup[i] = toupper(str[i]); } return strup; }[/cpp] [cpp]printf("%s", strtoupper("Character Stats")); // outputs 'CHARACTES STATS'[/cpp] Any ideas on what's causing this?[/QUOTE] sizeof(str) equals sizeof(char*) ,so you're not looking at the length of the string in any way.
I have this nearly complete grade-keeping program in Java that I was assigned in my computer science class. This is actually far beyond what the assignment wanted us to do so the teacher can't help me at all. Anyway, my problem is that when the program starts it creates this one main JFrame that keeps all the data, and I want to be able to save this one JFrame and load it up when the program starts. It does save/load, but it seemingly only loads some of the data in the JFrame. If this is what it looks like when I close the program (which then saves itself automatically) [img]http://i.imgur.com/WMdm1.png[/img] Then this is what it looks like when I start the program again (which loads the JFrame automatically) [img]http://i.imgur.com/YDtfr.png[/img] Also, the "Enter Student" button doesn't work, nor does the ActionListener on the JTextField for the input, meaning I can't enter any more students, and presumably that all ActionListeners for whatever reason don't work when it loads the .tmp file. It's split into 3 .class files, but this is the main file and handles the saving/loading. [code]import javax.swing.*; import java.awt.event.*; import java.io.*; public class GradeBook { private static JFrame frame; public static void main(String[] args) throws Exception{ try{ FileInputStream fis = new FileInputStream("t.tmp"); ObjectInputStream ois = new ObjectInputStream(fis); frame = (JFrame) ois.readObject(); ois.close(); } catch(Throwable t){frame = new JFrame("Course Grades");} frame.addWindowListener(new closing()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new CourseGrade()); frame.pack(); frame.setVisible(true); } private static class closing extends WindowAdapter{ public void windowClosing(WindowEvent e){ try{ FileOutputStream fos = new FileOutputStream("t.tmp"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(frame); oos.close(); } catch(Throwable t){System.out.println(t.getMessage());} } } }[/code] If I need to post the other two for you to help me I will but I didn't want to stretch the page too much with my shitty code.
Let's say I have 2 pairs of coordinates (x1,y1) and (x2,y2). First pair is the initial position, current pair is the current position. I can find out the distance and the slope but how do I use them do move an abject (let's say a circle) along the line made by the two pairs?
If your source point is (SX, SY) and your destination point is (DX, DY), you usually move the object along (SX + t * (DX - SX)), (SY + t * (DY - SY)) with t = 0.1
Won't that work only for a certain slope(say only positive). Also, is t constant or I have to increment it each time? I'm not familiar or don't fully understand that formula, maybe you can enlighten me :eng101:
the t is constant, it should work on every slope(I'm on phone so I can't test out) what it does is that it calculates the distance between the source and the destination point, and with the t constant you get the 1/10 of the distance to use that, you should store these numbers first and only once(MX,MY), and each time you update, you add these MX and MY to your SX and SY The only problem is that it will move with different speed over different distance, but if your distance is always the same then it won't cause much problems [editline]4th March 2012[/editline] The best formula that would work over different distances with the same speed is: [quote] If the mouse is at Mx,My and the ship is at Sx,Sy then calculate the direction from the ship to the mouse: [cpp]Dx=Sx-Mx Dy=Sy-My [/cpp] Now normalise D (this means scale it so that it's length is one): [cpp]DLen=sqrt(Dx*Dx + Dy*Dy) Dx/=DLen; Dy/=DLen;[/cpp] Now Dx is the distance you want to move the bullet on the x axis in order to get bullet speed of 1. Thus each frame you move the bullet like so (position of bullet: Bx,By Speed of bullet: Bs [in pixels per millisec] Frame time Ft[in millisec]) [cpp]Bx=Bx+Dx*Bs*Ft By=By+Dy*Bs*Ft[/cpp] This give you a bullet that moves towards the mouse position at a speed independent of the direction of the mouse or framerate of the game. [/quote] Source: [url]stackoverflow.com/questions/4848298/sfml-projectiles[/url]
Fuck I hate my professor. For this assignment I have to do, we're doing binary trees which are easy enough but he doesn't tell us how to construct the tree. I have to match his output exactly, or I'll lose a shitload of points because he's a fucking retard who can't admit there are other ways to do things. He just gives us numbers to insert into the tree and I don't know how he expects us to know where that data goes. I've been looking at this and it just looks like he put data wherever the fuck he wanted, but I don't know how to replicate his mental diarrhoea. I looked at the output we're supposed to match which contained the inorder, preorder, and postorder traversals of the tree, so I could draw a diagram of what it looked like. Obviously I can't use this traversal information to construct the tree because the traversal is the output, not the input. The data is given in this order: [code]{ 1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15 }[/code] Here are the traversals [code] inorder: -12 7 -4 11 -2 -10 -6 1 15 9 5 -14 3 13 -8 preorder: 1 -2 -4 7 -12 11 -6 -10 3 5 9 15 -14 -8 13 postorder: -12 7 11 -4 -10 -6 -2 15 9 -14 5 13 -8 3 1 [/code] Here's a diagram of the tree. [img]http://i.imgur.com/T3RBx.jpg[/img] I don't see any pattern here. Maybe I did the diagram wrong, but probably not. If nobody else can find a pattern, I'm just going to say fuck it and make a binary search tree (which it's not).
I don't see any pattern either. The tree clearly doesn't follow the usual rule that a node's left child is lesser and its right child is greater &#8212; if it did, the inorder traversal would have the numbers sorted from least to greatest &#8212; so it's not clear what rule it [i]does[/i] follow, if any. I can't can't think of any rational reason for why 7 should be the left child of -4, for example. Can't you ask your professor to explain?
Maybe 1 is not the root?
[QUOTE=James xX;34976204]I'm making my events.cpp file now, but I get linker errors when I use it. events.cpp [php] // Events.cpp #ifndef _EVENTS #define _EVENTS class Hook{ public: void Func( ); Hook( ){ }; }; class Event{ private: Hook* HookedEvents[255]; int AMT; public: Event( ){ AMT = 0; } ~Event( ){ } void AddHook( Hook* MyHook ){ AMT = AMT + 1; HookedEvents[ AMT ] = MyHook; } void Call( ){ int a = 1; for ( a = 1; a <= AMT; a++){ Hook* CurrentHook = HookedEvents[ a ]; CurrentHook->Func(); } } }; #endif [/php] Use: [php] // ... Event* OnDraw = new Event; // ... in a function OnDraw->Call(); // ... class MyDrawHook : public Hook { public: void Func(){ cout << "win"; } }; // In a function: MyDrawHook* MyDrawHook2 = new MyDrawHook; OnDraw->AddHook( reinterpret_cast<Hook*>(MyDrawHook2) ); [/php] any ideas? [Code] 1>Main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Hook::Func(void)" (?Func@Hook@@QAEXXZ)[/code][/QUOTE] Hook::~Hook and Hook::Func should be declared virtual. If you don't provide a definition for Hook::Func, then it should be declared pure virtual (i.e. virtual void Func() = 0;)
[QUOTE=high;34980260]You never allocate memory for strup. So you are probably getting some undefined behavior from writing to 'unallocated' memory.[/QUOTE] [cpp]char* strtoupper(char* str) { int i; size_t i_max = sizeof(str) * sizeof(char*); char* strup = (char*) malloc(i_max); for (i = 0; i < i_max; i++) { strup[i] = toupper(str[i]); } return strup; }[/cpp] That code outputs correctly, but is it possible to free() after returning the value? I can't free() before returning the value so I'm not too sure what to do here...
You could free it when you're done using it wherever you called the function from
[QUOTE=PvtCupcakes;34991627]Fuck I hate my professor. For this assignment I have to do, we're doing binary trees which are easy enough but he doesn't tell us how to construct the tree. I have to match his output exactly, or I'll lose a shitload of points because he's a fucking retard who can't admit there are other ways to do things. He just gives us numbers to insert into the tree and I don't know how he expects us to know where that data goes. I've been looking at this and it just looks like he put data wherever the fuck he wanted, but I don't know how to replicate his mental diarrhoea. I looked at the output we're supposed to match which contained the inorder, preorder, and postorder traversals of the tree, so I could draw a diagram of what it looked like. Obviously I can't use this traversal information to construct the tree because the traversal is the output, not the input. The data is given in this order: [code]{ 1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15 }[/code] Here are the traversals [code] inorder: -12 7 -4 11 -2 -10 -6 1 15 9 5 -14 3 13 -8 preorder: 1 -2 -4 7 -12 11 -6 -10 3 5 9 15 -14 -8 13 postorder: -12 7 11 -4 -10 -6 -2 15 9 -14 5 13 -8 3 1 [/code] Here's a diagram of the tree. [img]http://i.imgur.com/T3RBx.jpg[/img] I don't see any pattern here. Maybe I did the diagram wrong, but probably not. If nobody else can find a pattern, I'm just going to say fuck it and make a binary search tree (which it's not).[/QUOTE] I can relate to this kind of shit. My old professor was an 80+ year old lady who would do this shit on a daily basis. Ineligible instructions, way too much emphasis on pseudo-code and documentation etc. allowed for zero creativity or out of the box thinking, would dock points if the code differed from her horribly written psuedocode etc. etc. sucks man
[QUOTE=NovembrDobby;34992823]You could free it when you're done using it wherever you called the function from[/QUOTE] Wouldn't that mean having to make "strup" a global variable?
Nope, you're returning the pointer so you can just use that to delete it. Unless you're creating it on init and using it until the program ends? In that case you'll have to store it somewhere so you can delete it later.
[QUOTE=PvtCupcakes;34991627] Here's a diagram of the tree. [img]http://i.imgur.com/T3RBx.jpg[/img] [/QUOTE] |node.value| + |node.left.value| = (-1)*(node.right.value) That's all I can see at the moment.. [editline]4th March 2012[/editline] Hm then it wouldn't be valid for 3...
[QUOTE=Swebonny;34993542]|node.value| + |node.left.value| = (-1)*(node.right.value) That's all I can see at the moment.. [editline]4th March 2012[/editline] Hm then it wouldn't be valid for 3...[/QUOTE] Why not just |node.value| + |node.left.value| = |node.right.value| [editline]4th March 2012[/editline] at least to solve the issue with 3
Hey guys, I'm using the VS C++ 2011 beta and when I try to run sample code to check if I compiled SFML2 right I get an error saying that sfml-graphics-d-2.lib is missing when it's in all the correct places. I've done this before on 2010 version and put everything in the correct places and this never happened, anyone got any ideas? Edit: Solved by putting .dlls in debug folder.
How do you allow dragging and dropping into a docking area (if that's the right phrase) using the GWEN GUI? I want it like how it is in the sample, where you can drag a window into one of the top,left,right, or bottom docks and when when you're hovering over the area with the window it's highlighted pink so you know you can drop there. I can't figure it out from going through the source code and there's virtually no documentation, someone help, please. :( :'(
Sorry, you need to Log In to post a reply to this thread.