Can you post the (relevant) source in a pastebin or something so I can look at it? i want to test this out but dont want to write my own program to do it.
[QUOTE=sloppy_joes;46575970]Can you post the whole source in a pastebin or something so I can look at it?[/QUOTE]
sure, here's a paste of the three different files: loader.cpp, loaderTesting.cpp and grloader.h
[URL]http://pastebin.com/BS6di1UF[/URL]
just tested this in a new project using VS Express 2012 with the console program template, displays the same behaviour
oh and obviously make a text file with floats in it in the working directory
[QUOTE=Turnips5;46576049]sure, here's a paste of the three different files: loader.cpp, loaderTesting.cpp and grloader.h[URL]http://pastebin.com/BS6di1UF[/URL]just tested this in a new project using VS Express 2012 with the console program template, displays the same behaviouroh and obviously make a text file with floats in it in the working directory[/QUOTE] I dont have visual studio, so my solution just uses fscanf of fscanf_s. [url]http://pastebin.com/GnMbafJe[/url] Also I haven't done C++ in a while, but I fixed a few things for you. for example bool (full name boolean) is a type that only has true/false, so if you just want to return true false, just use boolean instead of int for your return type.
[editline]25th November 2014[/editline]
normally i would use ifstream to read from a file but the solution i just gave you is most like your own.
[editline]25th November 2014[/editline]
tell me if it worked though because im using gcc
ah, brilliant, thank you! I tried using fopen and fscanf in the first place, I got a compiler error telling me that these were deprecated functions and to use fopen_s and fscanf_s. I was reluctant to disable it but if the replacements are windows-exclusive, fuck it.
it works now, after I changed '%c' to '%s' in fscanf. (I tried it before, this didn't work with fscanf_s.) still no idea why it wasn't working before. yet another of life's stupid, stupid mysteries
The %c formatter expects a character pointer (char*) as an argument (so that it can set the character to whatever it reads). You are passing it a pointer to an array of 2 characters (which decays into a char**).
What you should do instead is have a single character that you read into, and then you compare that to another character, like this:
[code]char lineChar; //Note that this is a single character, not an array of 2 characters
fscanf_s(testFilePtr, "%c", &lineChar); //Same as what you have, but lineChar is a char
if (lineChar == 'g') //Compare 2 chars (instead of using strcmp to compare strings)
{
...
}[/code]
[QUOTE=Fredo;46576256]The %c formatter expects a character pointer (char*) as an argument (so that it can set the character to whatever it reads). You are passing it a pointer to an array of 2 characters (which decays into a char**).
What you should do instead is have a single character that you read into, and then you compare that to another character, like this:
[code]char lineChar; //Note that this is a single character, not an array of 2 characters
fscanf_s(testFilePtr, "%c", &lineChar); //Same as what you have, but lineChar is a char
if (lineChar == 'g') //Compare 2 chars (instead of using strcmp to compare strings)
{
...
}[/code][/QUOTE]
thanks for the explanation. I think this may be it, though I swear I tried something almost exactly like this before (with the single quotes for the char etc.)
[editline]26th November 2014[/editline]
ah, no, it looks like the issue was with my use of fopen_s. just changing that line to the fopen version fixes it in both your code and Joe's.
also, as i mentioned before, its generally considered best practice to use C++ objects and methods instead of C functions. for example fopen and fscanf are both C standard library functions, but you should use things like ifstream in a C++ program instead. you can read more here: [url]http://www.parashift.com/c++-faq-lite/iostream-vs-stdio.html[/url]
[editline]26th November 2014[/editline]
now that it works it doesn't really matter, but in the future you shouldn't use fopen and fscanf unless you have a legitimate reason for doing so.
-snip wrong thread ugh sorry-
[QUOTE=Turnips5;46576288]thanks for the explanation. I think this may be it, though I swear I tried something almost exactly like this before (with the single quotes for the char etc.)
[editline]26th November 2014[/editline]
ah, no, it looks like the issue was with my use of fopen_s. just changing that line to the fopen version fixes it in both your code and Joe's.[/QUOTE]
Your mistake was that, when you do
[cpp]
char lineChar[2]; //Create a char array to hold the first letter in the text file + null terminator
fscanf_s(testFilePtr, "%c", &lineChar); //Use fscanf_s to get first character in text file and place in lineChar
[/cpp]
It only sets the first character of lineChar, so the second character is pretty much a random variable.
When an string isn't ended with a null character the strcmp overflows and fails.
Before you added the second line, you where lucky and the compiler somehow managed to make sure that this variable is always null, when you added the second line recompiled you weren't so lucky and it wasn't null and the strcmp overflowed and failed.
All you need to do to make it work is explicitly end the string with a '\0'
[cpp]
char lineChar[2]; //Create a char array to hold the first letter in the text file + null terminator
fscanf_s(testFilePtr, "%c", lineChar); //Use fscanf_s to get first character in text file and place in lineChar
lineChar[1] = '\0';
[/cpp]
Its kinda interesting how passing a char ** to fscanf_s, when it expects a char* succeeds in this scenario, however its coincidence(or rather some stack alignment stuff) that it does it should actually be a char*.
[editline]26th November 2014[/editline]
Also generally, the CRT security features(_s) that micrsoft provides are the way to go unless you know what you're doing.
Which[URL="https://www.python.org/dev/peps/"] PEPs [/URL]should I definitely read?
In openGL, what is the most efficient way to do voxels?
Do I draw them on the geometry shader, draw them as instanced objects on the vertex shader, or do I pre bake all the voxels onto one VBO and send it over?
[QUOTE=thrawn2787;46574089]Then he wants a 2d array of a list or something.
[code]
// don't have to use vector, use whatever container you want
Vector<Foo>[][] array = new Vector<Foo>[y][x];
for(int i = 0; i < y; i++)
for(int j = 0; j < x; j++)
array[i][j] = new Vector<Foo>();
// now we can get our vectors and add stuff to them
array[0][0].add(new Foo());
[/code][/QUOTE]
How would you do this in Java?
[QUOTE=Talkbox;46579561]In openGL, what is the most efficient way to do voxels?
Do I draw them on the geometry shader, draw them as instanced objects on the vertex shader, or do I pre bake all the voxels onto one VBO and send it over?[/QUOTE]
GPUs vary too much for there to be one answer. But generally speaking, the speed difference between the first and third is negligible, and the second will be slow as fuck because you're not culling any occluded sides.
[editline]26th November 2014[/editline]
That being said, the first one requires the GPU to do a bit of extra calculations to create the necessary triangles, so it may be slower.
[QUOTE=NixNax123;46579562]How would you do this in Java?[/QUOTE]
That [I]is [/I]java.
[QUOTE=thrawn2787;46579774]That [I]is [/I]java.[/QUOTE]
That won't compile?
[editline]26th November 2014[/editline]
[code] // data
private final List<Entity>[][] data;
/**
* Constructs a grid with the specified boundary.
* @param boundary the boundary of the grid.
*/
public PartionedGrid(AABB boundary) {
this.boundary = boundary;
int edgeLength = (int)boundary.getRadius().x*2;
gridCellSize = edgeLength / 32;
data = new ArrayList<>()[edgeLength][edgeLength];
}
[/code]
[editline]26th November 2014[/editline]
[quote]array required, but java.util.ArrayList<java.lang.Object> found[/quote]
[QUOTE=Talkbox;46579561]In openGL, what is the most efficient way to do voxels?
Do I draw them on the geometry shader, draw them as instanced objects on the vertex shader, or do I pre bake all the voxels onto one VBO and send it over?[/QUOTE]
the set of [url=https://open.gl/]tutorials[/url] I've been following states suggests that the [url=https://open.gl/geometry]geometry shader[/url] is well-suited to this task
[QUOTE=Talkbox;46579561]In openGL, what is the most efficient way to do voxels?
Do I draw them on the geometry shader, draw them as instanced objects on the vertex shader, or do I pre bake all the voxels onto one VBO and send it over?[/QUOTE]
Divide the voxels in chunk smalls enough to rebuild a few off per frame without causing an hitch, then generate a VBO per chunk.
You can build the VBO on the GPU in a geometry shader, but you shouldn't do it each frame because its going to be significantly slower then just rendering a VBO, so you have to cache it in a feedback buffer if you do.
Doing it on the GPU would probably be better since it reduces the CPU->GPU bandwidth and will be faster in general, however doing on the CPU is probably more then fast enough, i personally wouldn't waste time on implementing it on the GPU.
[QUOTE=NixNax123;46579940]That won't compile?
[editline]26th November 2014[/editline]
[code] // data
private final List<Entity>[][] data;
/**
* Constructs a grid with the specified boundary.
* @param boundary the boundary of the grid.
*/
public PartionedGrid(AABB boundary) {
this.boundary = boundary;
int edgeLength = (int)boundary.getRadius().x*2;
gridCellSize = edgeLength / 32;
data = new ArrayList<>()[edgeLength][edgeLength];
}
[/code]
[editline]26th November 2014[/editline][/QUOTE]
Because you didn't look at the syntax right
[code]
data = new ArrayList<Entity>()[size][size]; // incorrect, calls array list constructor
data = new ArrayList<Entity>[size][size]; // correct, allocates a 2d array of array lists. note that
// all the elements in this 2d array are empty to begin with.
[/code]
And actually I was wrong you'll need to drop the generic
[code]
List<String>[][] data = new ArrayList[size][size];
[/code]
[QUOTE=thrawn2787;46580837]
[code]
List<String>[][] data = new ArrayList[size][size];
[/code][/QUOTE]
That is the completely wrong syntax. You cannot have a multi-dimensional ArrayList in Java. It'll either have to be an actual array, or a List that contains a wrapper class for the two values. Plus, you'll [B]want[/B] the generic identifier within the diamond braces.
[code]
public class StringContainer
{
public StringContainer(String first, String second)
{
this.first = first;
this.second = second;
}
//getters and setters...
private String first;
private String second;
}
[/code]
[code]
ArrayList<StringContainer> stringContainers = new ArrayList<StringContainer>();
[/code]
[QUOTE=Contron;46581279]That is the completely wrong syntax. You cannot have a multi-dimensional ArrayList in Java. It'll either have to be an actual array, or a List that contains a wrapper class for the two values. Plus, you'll [B]want[/B] the generic identifier within the diamond braces.
[code]
public class StringContainer
{
public StringContainer(String first, String second)
{
this.first = first;
this.second = second;
}
//getters and setters...
private String first;
private String second;
}
[/code]
[code]
ArrayList<StringContainer> stringContainers = new ArrayList<StringContainer>();
[/code][/QUOTE]That's what I thought. So I would need to make a separate class to handle coordinates and entity ID's, and put that into an ArrayList?
[editline]26th November 2014[/editline]
I think the simpler solution would just be to do what was said before, making a traditional 3D array that holds a max of 32 entities per cell.
Now I just need to make ID's for entities. Anyone care to get me started on that?
[QUOTE=NixNax123;46581624]That's what I thought. So I would need to make a separate class to handle coordinates and entity ID's, and put that into an ArrayList?
[editline]26th November 2014[/editline]
I think the simpler solution would just be to do what was said before, making a traditional 3D array that holds a max of 32 entities per cell.
Now I just need to make ID's for entities. Anyone care to get me started on that?[/QUOTE]
Simple. Make an enum class in java called entityType and in there, list your types in caps (for good style) - PLAYER, ASTEROID, BULLET, etc. Include a GENERIC as a base case as well. Then you can distinguish what an entity is by giving it a simple data member of entityType named id, and use a getter to retrieve it. Set it in the constructor of entity.
If you're looking to give every single entity on the screen a different id then that's a different story, but i'd question the necessity of that in the first place.
[QUOTE=Contron;46581279]That is the completely wrong syntax. You cannot have a multi-dimensional ArrayList in Java. It'll either have to be an actual array, or a List that contains a wrapper class for the two values. Plus, you'll [B]want[/B] the generic identifier within the diamond braces.
[/QUOTE]
It is a 2d array of array lists. There is absolutely nothing wrong with it if you want something that is 3d where only the innermost dimension can grow and shrink but not the outer dimensions. And it is 100% valid java
A better approach is probably a list of list of list. Or a class like:
[code]
class Foo
{
List<Bar> list = new ArrayList<Bar>();
}
Foo[][] ar;
[/code]
But my original approach seems to work fine
[editline]26th November 2014[/editline]
[QUOTE=killerteacup;46582339]Simple. Make an enum class in java called entityType and in there, list your types in caps (for good style) - PLAYER, ASTEROID, BULLET, etc. Include a GENERIC as a base case as well. Then you can distinguish what an entity is by giving it a simple data member of entityType named id, and use a getter to retrieve it. Set it in the constructor of entity.
If you're looking to give every single entity on the screen a different id then that's a different story, but i'd question the necessity of that in the first place.[/QUOTE]
Why not just have a list of IGameEntity or ICollideable or something. If all this quadtree gives a shit about is stuff that takes up area and can collide then they should inherit from something common and you make a list out of that
[editline]26th November 2014[/editline]
I'm not saying he's going down the right path for his overall assignment, I'm just answering his specific questions
Nax your teacher / professor / TAs are a better resource than facepunch / the internet.
[QUOTE=thrawn2787;46582656]It is a 2d array of array lists. There is absolutely nothing wrong with it if you want something that is 3d where only the innermost dimension can grow and shrink but not the outer dimensions. And it is 100% valid java
A better approach is probably a list of list of list. Or a class like:
[code]
class Foo
{
List<Bar> list = new ArrayList<Bar>();
}
Foo[][] ar;
[/code]
But my original approach seems to work fine
[editline]26th November 2014[/editline]
Why not just have a list of IGameEntity or ICollideable or something. If all this quadtree gives a shit about is stuff that takes up area and can collide then they should inherit from something common and you make a list out of that
[editline]26th November 2014[/editline]
I'm not saying he's going down the right path for his overall assignment, I'm just answering his specific questions
Nax your teacher / professor / TAs are a better resource than facepunch / the internet.[/QUOTE]
That's actually what I do on my games so you're 100% right. I actually wasn't entirely sure about the context of his question. If I needed to make each entity have an ID for generic purposes I probably would use enums but if its just for the use of a quadtree just grab everything from the list.
Is there a way to fetch the last message sent over Steam in Python?
[QUOTE=thrawn2787;46582656]It is a 2d array of array lists. There is absolutely nothing wrong with it if you want something that is 3d where only the innermost dimension can grow and shrink but not the outer dimensions. And it is 100% valid java
A better approach is probably a list of list of list. Or a class like:
[code]
class Foo
{
List<Bar> list = new ArrayList<Bar>();
}
Foo[][] ar;
[/code]
[/QUOTE]
I apologise, you're completely right. It does work, I just misread your post wrong. Sorry.
I've just never actually seen it been done like that so it's why I recommended having a container class of sorts.
So I've got this:
[code] // data
private final List<Entity>[][] grid;
/**
* Constructs a grid with the specified boundary.
* @param gridSize the size of the grid.
*/
public PartionedGrid(Vector2f gridSize) {
this.gridSize = gridSize;
gridCellSize = gridSize.x / 32;
rows = (int)((gridSize.y + gridCellSize - 1) / gridCellSize);
cols = (int)((gridSize.x + gridCellSize - 1) / gridCellSize);
grid = new ArrayList<Entity>[cols][rows];
}[/code]
Which won't compile.
How would I make this work without having a raw type for grid?
[QUOTE=NixNax123;46585797]So I've got this:
[code] // data
private final List<Entity>[][] grid;
/**
* Constructs a grid with the specified boundary.
* @param gridSize the size of the grid.
*/
public PartionedGrid(Vector2f gridSize) {
this.gridSize = gridSize;
gridCellSize = gridSize.x / 32;
rows = (int)((gridSize.y + gridCellSize - 1) / gridCellSize);
cols = (int)((gridSize.x + gridCellSize - 1) / gridCellSize);
grid = new ArrayList[cols][rows];
}[/code]
Which won't compile.
How would I make this work without having a raw type for grid?[/QUOTE]
As I said in my post above you need to exclude the generic on the rhs. I've edited the code in my quote
[editline]27th November 2014[/editline]
[QUOTE=Trebgarta;46587410]
I guess I can't simply post this here, so have some of the questions that bugged my mind for the past 2-3 hours.
What is compiling and decompiling to sum up(maybe I've got it wrong)? Why is it particularly hard to decompile a C++ file? What other languages can be decompiled better than C++, and why is that, what difference is there? How can I see the interior of dlls in any other way?
Also one last thing: Rise of Nations has a script editor, which has pre defined "trigger functions". All I wanted to find is where these are defined, and how they are defined. To learn from examples. Now , I have opened nearly every file that I can open with my Notepad++, and couldn't find anything. Any ideas?[/QUOTE]
Compiling = taking the written code and transforming it into something the computer actually understands (binary). Computers don't read C/C++/Java, they read binary.
Decompiling = taking compiled binary code and transforming it back into the language it came from.
Compilers do a shit ton of optimizations when compiling so it is very hard to recreate the original code most of the time.
If you are new to programming and want to learn I recommend learning by making your own programs rather than trying to reverse engineer existing things. Seems like you want to mod games. Go mod games that have mod support rather than trying to do weird hacky things with games that don't have mod support.
And if google yields nothing on finding where the rise of nations methods are defined then the devleopers have probably hidden them intentionally (aka only offered them as compiled code, not the source). Many programs do this. They will give you documentation as to what is [I]publicly [/I]exposed and how to use it but they do not give you access to the actual source code.
[url]http://stackoverflow.com/questions/448981/what-characters-are-valid-in-css-class-selectors[/url]
This solved it.
Hey guys, I'm working with Python and I have a question
I have a list of informations like this in a list:
['68', ' ?', ' 38317', ' 1st-4th', ' 2', ' Divorced', ' ?', ' Not-in-family', ' White', ' Female', ' 0', ' 0', ' 20', ' United-States', ' <=50K']
['32', ' ?', ' 293936', ' 7th-8th', ' 4', ' Married-spouse-absent', ' ?', ' Not-in-family', ' White', ' Male', ' 0', ' 0', ' 40', ' ?', ' <=50K']
aka list[1] would be: ['68', ' ?', ' 38317', ' 1st-4th', ' 2', ' Divorced', ' ?', ' Not-in-family', ' White', ' Female', ' 0', ' 0', ' 20', ' United-States', ' <=50K']
and list[2] would be: ['32', ' ?', ' 293936', ' 7th-8th', ' 4', ' Married-spouse-absent', ' ?', ' Not-in-family', ' White', ' Male', ' 0', ' 0', ' 40', ' ?', ' <=50K']
I want to only take the last bit of it, <=50K, how do I do that?
[QUOTE=thrawn2787;46587450]As I said in my post above you need to exclude the generic on the rhs. I've edited the code in my quote
[editline]27th November 2014[/editline]
Compiling = taking the written code and transforming it into something the computer actually understands (binary). Computers don't read C/C++/Java, they read binary.
Decompiling = taking compiled binary code and transforming it back into the language it came from.
Compilers do a shit ton of optimizations when compiling so it is very hard to recreate the original code most of the time.
If you are new to programming and want to learn I recommend learning by making your own programs rather than trying to reverse engineer existing things. Seems like you want to mod games. Go mod games that have mod support rather than trying to do weird hacky things with games that don't have mod support.
And if google yields nothing on finding where the rise of nations methods are defined then the devleopers have probably hidden them intentionally (aka only offered them as compiled code, not the source). Many programs do this. They will give you documentation as to what is [I]publicly [/I]exposed and how to use it but they do not give you access to the actual source code.[/QUOTE]
Removing the generic would just yield a raw data type warning. Which ends up in the list not being able to be used.
Sorry, you need to Log In to post a reply to this thread.