Vilusia needs some help with his Love2D game. He got Loveframes for working with UI stuff. I tried helping him make a store, but it seems that we're having some trouble with positions. I tried making a grid of imagebuttons parented to a frame, essentially the same way as derma, but it wasn't working out. Can someone with more (any) experience help him out with it?
[QUOTE=ZeekyHBomb;42140348]Yes.
How about smart-pointers though?[/QUOTE]
I might switch to those. Is there much overhead?
unique_ptr has none. There's some overhead for shared_ptr due to reference-counting, however it seems you need none, thus unique_ptr should do the job very well.
[QUOTE=WTF Nuke;42144800]I might switch to those. Is there much overhead?[/QUOTE]
Skipping std::auto_ptr which you should generally avoid (its copy semantic is screwed).
scoped_ptr: no overhead, cannot be copied or moved.
unique_ptr: no overhead, cannot be copied, can be moved.
shared_ptr / weak_ptr: some overhead (reference counting), can be copied.
From: [url]http://stackoverflow.com/questions/2454214/is-it-a-good-practice-to-always-use-smart-pointers[/url]
[editline]10th September 2013[/editline]
Damnit Zeeky even when I use google to answer a question you're faster.
cat /dev/internet > /dev/brain
[editline]10th September 2013[/editline]
btw, scoped_ptr is not part of C++11 (and afaik also not C++14).
Alright. From what I read it's a good idea to go unique_ptr for things that own memory, raw pointers for things that don't.
Anyone working with SFML.Net on MacOSX?
I want to be able to run my program and have all the needed sfml libraries with the exe, that is the csfml and the c++sfml libs but I have no idea how thats done in mac, I know in linux you can do the export LD_LIBRARY_PATH thing.
Also anyone know what the *.dll.config files should have in them?
[QUOTE=WTF Nuke;42146056]Alright. From what I read it's a good idea to go unique_ptr for things that own memory, raw pointers for things that don't.[/QUOTE]
In C++ you shouldn't use raw pointers at all. You can even get away from using malloc or new all together- make_shared and (easily added, forgotten in the standard) make_unique give you no chance of accessing the raw pointer without going through memory management.
I am using say a map for the management of meshes. I do not want to create a unique_ptr & every time I want to use the information in the mesh. Since I am not swapping ownership, using a unique_ptr would not work either.
Anyway, if anyone knows physx, I am completely stumped by this:
I have recently updated my game's internal object handling, such that I am able to load multiple meshes from a single .obj file. Although this seems irrelevant, it was so that I can bind rigid bodies to their graphical counterparts. Although this works, I have begun experiencing issues that do not make sense nor correlate to the changes made. Occasionally, one of the following bugs will occur:
*The controller or something goes wrong on creating, and spams me with error messages. I am unable to read the first few, but it always ends up with being unable to call raytraces from a dynamic actor (which I suspect is the controller's hidden actor, as this happens even when there are no other dynamic actors).
*The controller is unaffected by gravity, nor does it collide with static bodies. It does however collide with dynamic bodies, but these dynamic bodies are able to move inside the controller, and the controller cannot push them. Tests to see whether the controller is on the ground return false, however gravity should have an affect if this is the case (so it is not my gravity code's fault).
*The controller is rocketed into the air in the up vector, moving very very quickly. After mere seconds it is 10^12 units above the ground.
I have poured over every change made to my code, and after rigorous testing I am still not sure what the issue is. Attempts to recreate this bug on a source controlled version of the code before the upgrade (where this issue was not present) have been futile, and I have changed every aspect save for the part which creates multiple meshes instead of just one. This, however, should not affect the controller at all, as it does not even interact with the physics part of the code. What confuses me the most is that it only occasionally bugs out, as in it does not occur every time. This led me to believe it was a memory leak issue, but after making sure my code was leak proof via unique_ptrs and other methods, I have run out of ideas.
So basically I changed parts of code that don't affect other parts of code, but that other part is now not working, sometimes.
EDIT: Fixed the PhysX issue. I am a moron. Didn't initialize gravity to a number.
[QUOTE=Jookia;42147989]In C++ you shouldn't use raw pointers at all. You can even get away from using malloc or new all together- make_shared and (easily added, forgotten in the standard) make_unique give you no chance of accessing the raw pointer without going through memory management.[/QUOTE]
What about things that don't own memory where you can't control allocation of the thing you want to refer to?
Where should I start with learning SQL to use with MSSQL and Visual Basic? I want to get a head start for my new job and I'm mainly working with Databases
Sup gentlemen.
I'm taking computer science this year and my teacher assigned a programming assignment which I need to finish in less than 3 hours.
The problem is he didn't make any fucking sense when he was explaining it (he doesn't speak English well).
Here are the specifications he wrote on the board that I copied down.
o Write a simple program in Java to compute the number of chocolate spheres stacked in a triangular pyramid with x chocolate sphere layers (x is the number of layers required to make x layers).
o X is entered by user.
o Use N(x) = 1/6 x^3+1/2x^2+1/3x
o The volume V= 4/3pi*r^3
o Try x = 6, r=4; x=5, r=3
o Make sure to explain 4 phases/stages.
• Input phase
• Output phase
• Assumption and Formulation
• Constraints
He was up on the board explaining that if you were to stack chocolate spheres into a pyramid shape, you would need (for example) 4 on the bottom and 3 on top of that and 2 on top of that. Which makes sense. But then he threw in some bullshit volume formula and explained that "if you have bigger sphere then obviously it take less spheres to fill up layers."
If you're asking me to input the number of layers then it doesn't matter how big the spheres are. If they're going to make a triangular pyramid then I'm going to need the same amount of the spheres regardless of their size.
Any guesses? As of now I can't tell if he intended for me to stack the spheres into a simple 2D like triangle shape or if he intended a 3D triangular pyramid.
The assignment is faulty, but you can still make a program that outputs the number and total volume if it gets the layer count and radius.
Just have stacking layers, getting the volume of one sphere, getting the volume of all spheres and IO as phases maybe? I have no idea where the 4 is coming from.
You may have mixed up X and x at some point, too.
[QUOTE=thf;42153927]What about things that don't own memory where you can't control allocation of the thing you want to refer to?[/QUOTE]
Basically where you'd usually use 'new' or 'malloc', use shared pointers.
[CODE]import java.util.Scanner ;
import javax.swing.JOptionPane; // adds utilities from Java
public class PeiTest
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int age; // Interger Whole #
String name; // Letters used here
double gradePointAverage; // Decimal places
String projected_Grade; // Strings
JOptionPane.showInputDialog("Enter your name; ");// prompts user to enter their name
name =keyboard.nextLine(); // Reads whole line
JOptionPane.showInputDialog("Enter your age; ");// prompts user to enter their age
age =keyboard.nextInt(); // 1 interger
JOptionPane.showInputDialog("Enter your GPA; "); // prompts user to enter their GPA
gradePointAverage =keyboard.nextDouble(); // 2nd variable
JOptionPane.showInputDialog("What is your grade goal for this class?; ");// EnterExpectedG
projected_Grade = keyboard.next(); // inputs character it first reaches
JOptionPane.showMessageDialog(null, "Name; " + name + " Age " + age + " GPA " + gradePointAverage +
" Grade Goal; " + projected_Grade, projected_Grade, age, null);
}
}[/CODE]
In Java, I'm trying to have someone put in the information in the dialog boxes and afterwards have it display the dialog in a neat little box.
First college class about java and I'm stoked. Definitely need help. Originally in class we used System.out.printf("") but I want to tinker.
Any input would be appreciated.
Hey guys, I really need help for a project im making in C#, so the idea of this script is that you type the number of seconds you want and it tells you the number of days/hours/minutes and seconds that there is in these seconds. Currently it's not working and I really don't know why. Any of you have an answer?
[code] private void btnConvertirSecondes_Click(object sender, EventArgs e)
{
int iseconde;
int inbseconde;
int iminute;
int iheure;
int ijour;
iseconde = 0;
iminute = 0;
iheure = 0;
ijour = 0;
inbseconde = Formulaires.DemanderValeurInt("Nombre de seconde", "Seconde");
if (inbseconde < 86400)
{
if (inbseconde < 86400 && iseconde > 3600)//86400 secondes correspondent à 1 journée, si le nombre de seconde est en dessous, il n'y a pas de journée.
{
ijour = 0;
iheure = inbseconde / 3600;
iminute = (inbseconde - (3600 * iheure)) / 60;
iseconde = inbseconde - ((3600 * iheure) + (60 * iminute));
}
else
if (inbseconde < 3600 && iseconde > 60)//3600 secondes=1 heure
{
ijour = 0;
iheure = 0;
iminute = inbseconde / 60;
iseconde = inbseconde - (60 * iminute);
}
else
if (inbseconde < 60)//60 secondes=1 minute
{
ijour = 0;
iheure = 0;
iminute = 0;
iseconde = inbseconde;
}
}
else
{
ijour = inbseconde / 86400;
iheure = (inbseconde - (86400 * ijour)) / 3600;
iminute = (inbseconde - ((86400 * ijour) + (3600 * iheure))) / 60;
iseconde = inbseconde - ((86400 * ijour) + (3600 * iheure) + (60 * iminute));
}
MessageBox.Show("Jour:"+ijour+"\nHeure:"+iheure+"\nMinute"+iminute+"\nSeconde:"+iseconde);
}
[/code]
Ok Formulaires.DemanderValeurInt is going to make appear a dialog box where you can put the number you want. Also this is in visual studio.
[editline]12th September 2013[/editline]
Also, jour = days, heure = hour, minute = minute and seconde = second.
[QUOTE=blacksam;42160062][CODE]import java.util.Scanner ;
import javax.swing.JOptionPane; // adds utilities from Java
public class PeiTest
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int age; // Interger Whole #
String name; // Letters used here
double gradePointAverage; // Decimal places
String projected_Grade; // Strings
JOptionPane.showInputDialog("Enter your name; ");// prompts user to enter their name
name =keyboard.nextLine(); // Reads whole line
JOptionPane.showInputDialog("Enter your age; ");// prompts user to enter their age
age =keyboard.nextInt(); // 1 interger
JOptionPane.showInputDialog("Enter your GPA; "); // prompts user to enter their GPA
gradePointAverage =keyboard.nextDouble(); // 2nd variable
JOptionPane.showInputDialog("What is your grade goal for this class?; ");// EnterExpectedG
projected_Grade = keyboard.next(); // inputs character it first reaches
JOptionPane.showMessageDialog(null, "Name; " + name + " Age " + age + " GPA " + gradePointAverage +
" Grade Goal; " + projected_Grade, projected_Grade, age, null);
}
}[/CODE]
In Java, I'm trying to have someone put in the information in the dialog boxes and afterwards have it display the dialog in a neat little box.
First college class about java and I'm stoked. Definitely need help. Originally in class we used System.out.printf("") but I want to tinker.
Any input would be appreciated.[/QUOTE]
You seem to be prompting in a GUI component but expecting input to be available from the standard input descriptor (which is usually a text-based console of some sort). The static method `showInputDialog` should return a String (so if a user inputs 3.0 you will get the string "3.0"). You have to do the parsing yourself in order to get a different type. For example:
[code]
double gradePointAverage;
String input = JOptionPane.showInputDialog("Enter your GPA; "); // prompts user to enter their GPA
gradePointAverage = Double.parseDouble(input); // 2nd variable
[/code]
The fundamental types each have a related class (byte has Byte, double has Double, etc. etc.) which has a static `parseType(String)` method which will try to make sense of input in terms of the type. Check out the javadocs for more information on them.
Needless to say you don't need the Scanner object if you are working entirely with swing components.
I'm loading PhysX objects from a file. There are meshes with rigid bodies attached to them. Some of these meshes have their rigid bodies rotated, others do not. This means that an object could look the same as another object, but have different rotation, as Maya will export them based on their base mesh (so this mesh can be either rotated superficially, or have the rotation applied). I poll the rotation of the PhysX object each frame, to see how the mesh's rotation should change. What my issue is, is that I am not sure how to apply the rotation. Nor am I sure how to interpret the data as the data might be based from an already rotated mesh(one that corresponds with the .obj points of data) or one that is not rotated(one that corresponds with the unrotated mesh). I thought that I can store the original rotation, and then do an inverse rotation of that before I rotate by the objects rotation, however this has been fruitless. The code is as follows:
This changes the object's origin, and is called when the mesh is first read. ptog() is a helper function that converts PhysX data types to their corresponding GLM equivalents.
[cpp]void Model::setOrigin(PxTransform & tran){
posOrigin = ptog(tran.p);
rotOrigin = glm::inverse(ptog(tran.q));
}[/cpp]
This is what updates the mesh's matrix
[cpp]matrix = glm::mat4(1.0);
matrix = glm::translate(matrix, position);
matrix *= glm::toMat4(rotation * rotOrigin);
matrix = glm::scale(matrix, scale);
matrix = glm::translate(matrix, -posOrigin);[/cpp]
The reason why there is a translation first(or last visually) is because the rigid body from PhysX is translated, where as the mesh I read is translated with it's data points, and thus has no intrinsic translation. That way, I translate back to the origin of the mesh, so that the rotation makes sense, as does the position of the model.
[QUOTE=bilbasio;42160848]-snip-[/QUOTE]
Pragmatic solution: Use TimeSpan and [URL="http://msdn.microsoft.com/fr-fr/library/vstudio/ee372287.aspx"]format it[/URL]. That does everything you need in one line.
Manual solution:
Instead of all these ifs and subtraction it would be easier to get the remainder of the division with the next larger time span, so [code]int days = input / secondsInADay;
int hours = input % secondsInADay / secondsInAnHour;
...[/code]
Please fix your variable naming: You're using systems hungarian (prefixing with the type), which is commonly regarded as extremely bad style because it interferes with intellisense and makes code less readable. Apps hungarian (prefixing with usage) is fine.
Don't make variables all lower case in C#, make word boundaries more apparent with lowerCamelCase.
Use constants for your repeated "magic numbers", they compile to the same code but you don't need the comments everywhere because the code becomes self-documenting.
[editline]edit[/editline]
[u]Never[/u] initialize your variables to defaults before using them properly (unless there is an actual default value that can appear).
It completely breaks the safety mechanism that prevents nonsensical values from being returned usually.
Declaring them all at the top of the method is a bit strange too, that's not the usual C# style.
[editline]edit[/editline]
If you have something like this:[code]"Jour:"+ijour+"\nHeure:"+iheure+"\nMinute"+iminute+"\nSeconde:"+iseconde[/code], it would be better to format it instead of using string concatenation:
[code]string.Format("Jour:{0}\nHeure:{1}\nMinute{2}\nSeconde:{3}", ijour, iheure, iminute, iseconde)[/code]
as strings in .NET have some overhead when being created and the normal method has a lot of intermediary steps.
[editline]edit[/editline]
The error in your code are the branch conditions by the way. Checking for > 60 in one case and < 60 in the other means that 60 falls through all cases.
You also used the wrong variable there, probably due to the systems hungarian.
This is precisely the error that not initializing the variables with defaults would prevent,
as it would force you to pick sensible branch conditions (no useless and wrong re-checking) and to use the correct variable.
[editline]edit[/editline]
I guess my point is this: Please use a more sensible coding style, as then the compiler is very often able to pinpoint the exact location of your mistake.
Right now you are much more likely to have problems like this because your style deactivates safety mechanisms and assists.
Unable to post
[QUOTE=CRASHFORT;42162565]Unable to post[/QUOTE]
I think the captcha is fake, I only input one word the last two times and it let me pass :v:
[QUOTE=Jookia;42159645]Basically where you'd usually use 'new' or 'malloc', use shared pointers.[/QUOTE]
Yes, but if allocation is done through a function that returns a pointer? Or it is allocated in the stack.
[QUOTE=thf;42162990]Yes, but if allocation is done through a function that returns a pointer? Or it is allocated in the stack.[/QUOTE]
If you're expected to delete it somehow, smart pointer.
Otherwise, check for nullptr and then store a reference to *ptr.
Hey guys, I have a small question for you.
Why can't I simply do
[code]#include <gstreamer-0.10/gst/gst.h>[/code]
in my code to include GStreamer? I want to experiment with it using C++ but I can't even include it because it cries all the time. My compiler flags are:
[code]g++ -o build main.cpp -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include[/code]
I am developing on Linux, by the way.
Learn [url=https://www.gnu.org/software/make/]Make[/url], or [url=http://www.cmake.org/]CMake[/url] or something.
Before I learned that I had an executable file called fakemake, which simply did stuff like
[code]g++ -Wall -Wextra -pedantic *.cpp `pkg-config --cflags --libs gstreamer-0.10 glib-2.0`[/code]
[editline]12th September 2013[/editline]
[url=http://facepunch.com/showthread.php?t=1250528&p=40662072&viewfull=1#post40662072]Here's some Makefile I posted a while back[/url] if you want to get started with GNU Make.
I've switched to CMake for my projects though.
Alright, thanks Zeeky - you've been of help. I might come back to this thread since I am just a beginner programmer.
can anyone recommend me any good books for learning C++? i know there is an extensive list of tutorials on the web to use, but i think i'll get a better grasp studying a book, opposed to hopping from tutorial to tutorial.
Yes, I would recommend a book over an internet tutorial if it's your first language.
I remember people on this forum recommending Accelerated C++. I can't say anything about it, since I have not read it.
I've had good success with Learn C++ in 21 Days (iirc), which is now called Learn C++ an Hour a Day (or something like that); I've also seen it being updated to the latest C++ standard, called C++11.
Effective C++ is an excellent intermediate book. If you feel you're getting fluent in C++ I can highly recommend it.
Here's a somewhat tricky and somewhat silly one. At least, it seems tricky to me.
So for a project of mine, I'm using the Jim TcL implementation of TcL, and I'm currently attempting to build it with tcc. Yes, I know, bare with me here.
[code]
CC=tcc ./configure && make CC=tcc
[/code]
It spits out the following error though:
[code]
tcc -g -O2 -c -o _load-static-exts.o _load-static-exts.c
In file included from _load-static-exts.c:3:
jim.h:82: error: include file 'jim-win32compat.h' not found
[/code]
I have a few other errors in some projects, compiling stuff with tcc is without a doubt not ideal. At least, that goes for a lot of the software out there. This one stands out a bit though. Mainly because jim-win32compat.h is in the main directory if the jimtcl directory, where jim.h is also being included.
It might be that it's included via <>and gcc silently accepts that, or tcc does not include the current path when including with "".
Anyway, to work around whatever the issue is, add CFLAGS=-I<path-to-jim-win32compat.h> to the configure invocation.
Sorry, you need to Log In to post a reply to this thread.