You're getting a stack overflow. Allocate the buffer using malloc(), or by using a C++ vector.
You'll still be limited by how much stack space you have with this, so a better idea still is this:
[cpp]
colour* pixels = (colour*)malloc(width*height*sizeof(colour));
[/cpp]
[editline]02:56PM[/editline]
:ninja:
Yeah, I posted before I thought and then ninja edited before you posted. :ninja:
And to use that for a multi-dimensional array i'd have to use pointers of pointers?
[cpp]colour **bmp_data = (colour**)malloc(width*sizeof(colour *));
for(int i=0; i<height; i++)
{
bmp_data[i] = (colour*)malloc(height*sizeof(colour));
}[/cpp]
Like so?
EDIT: That crashes still.
[QUOTE=FerrisWheel;24053652]And to use that for a multi-dimensional array i've have to use pointers of pointers?
[cpp]bmp_data = (colour**)malloc(width*sizeof(colour *));
for(int i=0; i<height; i++)
{
bmp_data[i] = (colour*)malloc(height*sizeof(colour));
}[/cpp]
Like so?[/QUOTE]
No. You could, but that's sloppy.
Use this:
[code]
bmp_data = (colour*)malloc(width*height*sizeof(colour));
/* Access with */
bmp_data[y*width+x];
[/code]
Also remember to call free() on the buffer when you're done with it. Buffers created with malloc() aren't like arrays. They do not disappear when the function exits. You need to manually free the buffer when you are done using it.
[QUOTE=ROBO_DONUT;24053703]
[code]
bmp_data = (colour*)malloc(width*height*sizeof(colour));
/* Access with */
bmp_data[y*width+x];
[/code][/QUOTE]
That's a good way of using the index to act like a multi-dimensional array, thanks alot. Program works like a charm now. Thanks for the help.
[QUOTE=FerrisWheel;24053872]That's a good way of using the index to act like a multi-dimensional array, thanks alot. Program works like a charm now. Thanks for the help.[/QUOTE]
No prob. :)
[QUOTE=Robert64;24041481]I'm stuck with a weird error with lua.
Basically I have a lua table, ENT, with its metatable's index set to an instance of a C# class (userdata).
In the lua table is this function:
-snip-
In the C# class is this function:
-snip-
But when trying them both out I get this:
-snip-
ent.TestFunc2 definitely exists. Also public variables in the C# class can be printed fine with ent.VarName.
What could be the problem?[/QUOTE]
Post the code which assigns the __index field.
I need to convert a big-endian file to little-endian, and I've read that using a byte swapping method is far quicker than Array.reverse(), so I took the example code and used it for a 4 byte swap instead of the sample 8 byte swap. Visual Studio returns 3 errors, "Method name expected," and only the first three uNum parenthesis segments return the error, apparently the 4th one is just fine...
[cpp] private int convertToLittleEndian(int i)
{
uint uNum = (uint)i;
uint swappedNum = ( (0x000000FF) & (uNum >> 24)
(0x0000FF00) & (uNum >> 8)
(0x00FF0000) & (uNum << 8)
(0xFF000000) & (uNum << 24) );
return (int)swappedNum;
}[/cpp]
[editline]01:50AM[/editline]
Basically, how do I clear 3 errors that apppear at:
(uNum >> 24)
(uNum >> 8)
(uNum << 8)
[editline]02:18AM[/editline]
figured it out, the example decided to omit the | operator at between each shift operation. I found a very similar piece of code on another website with the | operator, so I added it and it works.
I'm still a bit confused as to the byte order of the file, there's references to a file and now those are all mangled. There's also a section towards the end of the file which as the letters A - Z repeating several times,seperated by different symbols, like %, `, and #, as well as a bunch of accented letters and symbols seperated by 0x1C (appears as a space), arrows pointing up, down, left, and right, etc, and now the letters are in a different order.
I'm completely unsure as to what that's supposed to be interpreted as.
I'm going to upload a sample file to see if anyone can help me..
[editline]02:21AM[/editline]
Here's a moderately sized one I'm testing: [url]http://www.mediafire.com/?9epzyxx8xzatba1[/url]
and here's the smallest one in the game: [url]http://www.mediafire.com/?c4p5iq44cv4qdhi[/url]
How do I get a progress bar work on a timer in Visual Basic 2008?
[QUOTE=robmaister12;24055770]I need to convert a big-endian file to little-endian, and I've read that using a byte swapping method is far quicker than Array.reverse()[/QUOTE]
Byte-swapping and Array.reverse() don't do the same thing, and you can't change the endianness of a file without knowing how it's structured.
Suppose you have a file that contains these eight bytes:
[code]00 01 02 03 04 05 06 07[/code]
If these bytes represent two 32-bit integers, you need to reverse each group of four bytes, to get
[code]03 02 01 00 07 06 05 04[/code]
But if it represents four 16-bit integers, you need to reverse each group of two bytes, to get
[code]01 00 03 02 05 04 07 06[/code]
and if it represents just a sequence of bytes (e.g. a string) then you don't need to change anything.
Combinations are possible. If the bytes in the file represent one 32-bit integer followed by two 16-bit integers, you need to reverse one group of four and two groups of two, like so:
[code]03 02 01 00 05 04 07 06[/code]
In no case is reversing the entire file (e.g. Array.reverse()) the right thing to do.
[QUOTE=a-cookie;24058077]How do I get a progress bar work on a timer in Visual Basic 2008?[/QUOTE]
Figure it out yourself.
[QUOTE=Wyzard;24058266]Byte-swapping and Array.reverse() don't do the same thing, and you can't change the endianness of a file without knowing how it's structured.
Suppose you have a file that contains these eight bytes:
[code]00 01 02 03 04 05 06 07[/code]
If these bytes represent two 32-bit integers, you need to reverse each group of four bytes, to get
[code]03 02 01 00 07 06 05 04[/code]
But if it represents four 16-bit integers, you need to reverse each group of two bytes, to get
[code]01 00 03 02 05 04 07 06[/code]
and if it represents just a sequence of bytes (e.g. a string) then you don't need to change anything.
Combinations are possible. If the bytes in the file represent one 32-bit integer followed by two 16-bit integers, you need to reverse one group of four and two groups of two, like so:
[code]03 02 01 00 05 04 07 06[/code]
In no case is reversing the entire file (e.g. Array.reverse()) the right thing to do.[/QUOTE]
I've tried both, I gain a little bit of readability and lose some.
Regardless, I've been digging through some XML files hoping to get a hint at what it resembles, and it looks like I've hit the jackpot...
[code]<ResourceConfig>
<Resource Class="CGeometryResource" SourceExt=".glm" TargetExt=".xbg" />
<Resource Class="CTextureResource" SourceExt=".dds;.png" TargetExt=".xbt" />
<Resource Class="CAnimationResource" SourceExt=".mac" TargetExt=".mab" CompileDependency=".mkai;.mks;.mkfx" />
<Resource Class="CSkeletonResource" SourceExt=".skel.xml" TargetExt=".skeleton" />
<Resource Class="CFaceActorResource" SourceExt=".fxa" TargetExt=".lfa" />
<Resource Class="CFaceAnimResource" SourceExt=".fxe" TargetExt=".lfe" />
<Resource Class="CPhysResource" SourceExt=".hkr" TargetExt=".hkx" />
<Resource Class="CRealtreeResource" SourceExt=".rta" TargetExt=".rtx" />
<Resource Class="CFrankensteinPoseResource" SourceExt=".frank" TargetExt=".apm" />
<Resource Class="CStateMachineResource" SourceExt=".gosm.xml" TargetExt=".gosm.xml" />
<Resource Class="CMaterialResource" SourceExt=".mlm" TargetExt=".xbm" />
<Resource Class="CSectorResource" SourceExt=".gsdat" TargetExt=".sdat" />
<Resource Class="CBinkResource" SourceExt=".bik" TargetExt=".bik" />
<Resource Class="CAIWorkspaceResource" SourceExt=".ai.xml" TargetExt=".ai.rml" />
</ResourceConfig>[/code]
This basically explains their entire file naming layout. Granted, most of their files have headers attached to them, but it's relatively the same.
Meaning that the model files are essentially .glm files, and using google I tracked down a program with that format, [url=http://www.dynoinsight.com/ProDown.htm]DInsight KernelCAD[/url]
I'm going to try and make sense of the .glm format then see what Ubisoft packed it on with.
[QUOTE=turb_;24058440]Figure it out yourself.[/QUOTE]
I got told how to, I just forgot..
[QUOTE=jA_cOp;24055417]Post the code which assigns the __index field.[/QUOTE]
Essentially it's just:
[lua]setmetatable( lua_table, { __index = CSharpObject })[/lua]
Although what I did had to be a bit more complicated then that.
[editline]02:44PM[/editline]
Variables in the CSharpObject work fine, but not functions.
[QUOTE=robmaister12;24055770][cpp] private int convertToLittleEndian(int i)
{
uint uNum = (uint)i;
uint swappedNum = ( (0x000000FF) & (uNum >> 24)
(0x0000FF00) & (uNum >> 8)
(0x00FF0000) & (uNum << 8)
(0xFF000000) & (uNum << 24) );
return (int)swappedNum;
}[/cpp]
[/QUOTE]
You forgot to combine them with a bitwise-or:
[cpp] private int convertToLittleEndian(int i)
{
uint uNum = (uint)i;
uint swappedNum = ( ((0x000000FF) & (uNum >> 24)) |
((0x0000FF00) & (uNum >> 8)) |
((0x00FF0000) & (uNum << 8)) |
((0xFF000000) & (uNum << 24)) );
return (int)swappedNum;
}[/cpp]
In C# I have two classes like this:
[cpp]class ClassA
{
public static int X = 25;
public static void Bluh()
{
Console.WriteLine( X );
}
}
class ClassB : ClassA
{
public new static int X = 50;
}[/cpp]
When I call ClassA.Bluh() I get 25 as expected. Is there a way to get 50 when I call ClassB.Bluh() without defining Bluh() again in ClassB?
[editline]05:52PM[/editline]
The closest I can get is this:
[cpp]class ClassA
{
public static int X = 25;
public static void Bluh( Type t )
{
Console.WriteLine( t.GetField( "X", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public ).GetValue( null ));
}
}
class ClassB : ClassA
{
public new static int X = 50;
}[/cpp]
Which is ugly and I have to call it like:
[cpp]ClassB.Bluh( typeof( ClassB ) );[/cpp]
Well, why would you do that on a static class anyway?
I think I'm finally getting somewhere with OpenGL, this time it's actually a shader logic question!
So, I have this vertex shader:
[code]#version 110
attribute vec2 position;
varying vec2 texcoord;
void main() {
gl_Position = vec4(position, 0.0, 1.0);
texcoord = position * vec2(0.5) - vec2(0.5) ;
}[/code]
I understand what it does, dividing the position by 2 since it ranges from -1,-1 to 1,1 and then substracting 0.5,0.5 for make it fill the window.
Unfortunately the texture is flipped vertically, I guess I could find how to fix that outside of the shader (even flipping the image it self) but I want to do it inside it. I tried to do this:
[code]
texcoord = (position * vec2(0.5) + vec2(0.5)) * vec2(0.0, -1.0) ;[/code]
but is just stretches the image in a weird way. Doing vec2(-1.0, 0.0) stretches is also but vertically. The strange thing is that multiplying it with vec2(-1.0, -1.0) flipps it horizontally AND vertically.
Why doesn't it work and how do I fix it?
[editline]10:30PM[/editline]
Oh wow, now I fell stupid.
Multiplying it with zero and what not.
Won't even snip it.
[QUOTE=Robert64;24062683]In C# I have two classes like this:
-snip-
When I call ClassA.Bluh() I get 25 as expected. Is there a way to get 50 when I call ClassB.Bluh() without defining Bluh() again in ClassB?
[editline]05:52PM[/editline]
The closest I can get is this:
-snip-
Which is ugly and I have to call it like:
[cpp]ClassB.Bluh( typeof( ClassB ) );[/cpp][/QUOTE]
You can't achieve this kind of polymorphism with static fields and functions, nor is there any reason to do it. You should rethink your approach (or just tell us what you [I]actually[/I] want to do so we can suggest a good approach).
[QUOTE=Robert64;24059650]Essentially it's just:
[lua]setmetatable( lua_table, { __index = CSharpObject })[/lua]
Although what I did had to be a bit more complicated then that.
[editline]02:44PM[/editline]
Variables in the CSharpObject work fine, but not functions.[/QUOTE]
Well, I doubt anyone can help you without getting to look at the offending code.
Did notch ever release the minecraft server code?
i read somewhere that he was planning on releasing the server code as open source
[QUOTE=Richy19;24069586]Did notch ever release the minecraft server code?
i read somewhere that he was planning on releasing the server code as open source[/QUOTE]
It would be great to just have the map generation code.
Someone on here was making an awesome map viewer an was apparently going to release the code
haven't heard anything for a couple weeks about it thou
I'm trying to write data from one form to another and save it as a text file, and I had it working at one point but, lucky me, forgot to save it.
What I'm trying to do more specifically: On form1 there is a TextBox and a button, on form2 there is a listbox that's contents are auto-loaded from a text file. (That part works), but I'm trying to write to that text file from form1 with that button on form1.
Oh yeah, Visual Basic.
[code]
Dim newBook(Me.TextBox1.Text) As String
Form2.ListBox1.Items.CopyTo(ItemArray, 0)
Dim Data As String = Join(ItemArray, Environment.NewLine)
Dim newdata As String = Join(newBook, Environment.NewLine)
My.Computer.FileSystem.WriteAllText("settings\textfile.txt", newdata, False)
[/code]
..Not quite sure what I'm doing above..pissing in the wind. Here's the code for form2's listbox.
[code]
ListBox1.Items.AddRange(Split(My.Computer.FileSystem.ReadAllText("settings/textfile.txt"), vbNewLine))
[/code]
That's on formload event, and it works fine. Any help?
I haven't touched Visual Basic in years, but I'm pretty sure there's a StreamWriter object you can use to save data to a file, line by line.
[editline]12:20AM[/editline]
I felt like taking a foray into SFML and making sure my C++ doesn't get too rusty (I went to a 1 week summer camp for game design in C++, except we used DarkGDK, which is total shit (takes a full minute to load a very simple .x file).
I grabbed the latest revision from SVN, did all the compiling and configuration setup in Visual Studio, and I'm following their basic tutorial to create a window and close it when the Escape key is pressed. However, when I debug it, my computer makes a somewhat high pitched screeching sound, what's going on? :tinfoil:
[editline]12:25AM[/editline]
the pitch and volume seems to change with window size too... this is quite strange.
[editline]12:48AM[/editline]
enabling vsync seems to have fixed it.. I guess my FPS was way too high or something.
In C# you'd do
TextWriter file = new StreamWriter("file.txt", true); // That true is there because otherwise it'd recreate the file every time
file.WriteLine("Whatever");
file.Write("What").
file.Close();
Shouldn't be much more different in VB
-snip-
I should google things more often...
[QUOTE=robmaister12;24078467]However, when I debug it, my computer makes a somewhat high pitched screeching sound, what's going on? :tinfoil:
[editline]12:48AM[/editline]
enabling vsync seems to have fixed it.. I guess my FPS was way too high or something.[/QUOTE]
Happens to me too sometimes, if you have a really high framerate some graphics cards will squeal
[QUOTE=NovembrDobby;24081408]Happens to me too sometimes, if you have a really high framerate some graphics cards will squeal[/QUOTE]
Mine also does this, when I'm going in an infinite loop. :tinfoil:
[QUOTE=jA_cOp;24069490]You can't achieve this kind of polymorphism with static fields and functions, nor is there any reason to do it. You should rethink your approach (or just tell us what you [I]actually[/I] want to do so we can suggest a good approach).
I'm trying to save having to repeat code within my resource system. This might take a while to explain.
It currently works with resource files (.lres) structured like this:
[code][directory/somefile.lres]
"ResourceItemClass"
{
"item_1_name" "param1" "param2" "etc" ;
"item_2_name" "param1" "param2" "etc" ;
"item_3_name" "param1" "param2" "etc" ;
}[/code]
The first part in square brackets loads another similar .lres file. The "ResourceItemClass" sets which type of resource the following items are loaded as. It relates to a Resource class in C# which is in the Resource namespace and named, in this example RResourceItemClass. The same as the name above but with an R at the start to make it easy to identify in C#.
When each item is read from the .lres file it will call the constructor of RResourceItemClass, passing the params. Examples of real resource classes are RSprite, RAnim, RText and RLua.
I have C# automatically finding all the Resource.RWhatever files when the program runs, so I don't need to add them to a list manually when I add a new resource type.
As I mentioned before, there is an RLua resource class which accepts the path to a .lua file as the parameter. The created instance of RLua handles running its loaded .lua file, and attaching hooks etc.
There is another resource class called RLuaResource which is never used as it is, but is extended for other resource classes that will use Lua for in-game logic. Examples of this are REntity and RFoliage. I have RLuaResource automatically creating a "class" table for Lua to use along the lines of ENT for Entity (like in GMod). After the Lua file has ran, setting up functions and variables on the table, RLuaResource prepares the table for use in individual entities where it will create an empty table and set the metatable to index the Lua generated table.
For example, here is the relevant code for RFoliage:
[cpp]class RFoliage : RLuaResource
{
public new static String LuaIdentifyer = "FOL";
private uint my_growthtime;
private double my_frequency;
private int my_group_size;
private int my_group_spread;
private bool my_appear_wild;
private bool my_appear_tame;
private RTileSet my_tileset;
public static void ConfigureBaseTable( LuaTable base_table )
{
base_table[ "GrowthTime" ] = 1000000;
base_table[ "AppearInWild" ] = true;
base_table[ "AppearInTame" ] = true;
base_table[ "Frequency" ] = 0;
base_table[ "GroupSize" ] = 0;
base_table[ "GroupSpread" ] = 0;
base_table[ "TileSet" ] = "fol_tree_apple";
}
public RFoliage( List<String> n )
: base( n )
{
}
public void ConfigureClassTable( LuaTable class_table )
{
my_growthtime = Convert.ToUInt32( class_table[ "GrowthTime" ] ) * 1000;
my_appear_wild = Convert.ToBoolean( class_table[ "AppearInWild" ] );
my_appear_tame = Convert.ToBoolean( class_table[ "AppearInTame" ] );
my_frequency = Convert.ToDouble( class_table[ "Frequency" ] );
my_group_size = Convert.ToInt32( class_table[ "GroupSize" ] );
my_group_spread = Convert.ToInt32( class_table[ "GroupSpread" ] );
my_tileset = Res.GetItem<RTileSet>( Convert.ToString( class_table[ "TileSet" ] ) );
}
public override LuaTable CreateInstanceTable( object self, params object[] args )
{
return Initialize( "Entity", self );
}
}[/cpp]
LuaIdentifyer is basically X from the question I asked before. When the program starts it searches for Resource classes, and calls the static function InitializeResource in the Resource class if it has one. RLuaResource does, and searches for classes which extend it like RFoliage, sets up a default Lua table and calls ConfigureBaseTable in the class. In order to set up the base table RLuaResource needs to know what abbreviation to call it (like ENT before). That's where LuaIdentifyer comes in, RLuaResource finds the value of LuaIdentifyer in the child class and uses it. It basically saves me retyping a lot of code each time I want to create a resource object that uses Lua. It all works anyway, so I don't really need an answer any more but I would like to know if this is an awful way to do it.
Sorry, you need to Log In to post a reply to this thread.