[QUOTE=calzoneman;37421884]When the textbox is focused and its text is the default text, clear it. When the textbox is blurred (loses focus) and the text is blank, fill in the default text.[/QUOTE]Yeah, I got that. But I don't know how to make all the textboxes go to a single event.
I just don't want 5 of these
[img]https://dl.dropbox.com/u/1439918/Pics/2012-08-29_20-50-25.png[/img]
-snip-
I'm messing with Lua in Love2D and I'm trying to figure out how to do usable objects.
Right now I'm using Tiled to place a tile with "use 1" as it's property and checking for that. That works but I need a system for setting up the objects.
Give them like a name, description, and functions to call when the player presses the use key when facing it.
Just need some ideas on best way to do this and to get me motivated to do more.
[QUOTE=TehWhale;37462096]Yeah, I got that. But I don't know how to make all the textboxes go to a single event.
I just don't want 5 of these
-img-[/QUOTE]
Just set a field for the textbox class for "default" and add that in to the regular gain/lose focus functions?
[QUOTE=Mordi;37456574]I'm getting HEAP CORRUPTION ERROR (in caps, mind you).
I'm sure it has to do with resource-releasing/freeing, but I can't see how I am releasing any resources twice. However, I may be attempting to free a pointer to a resource rather than the resource itself, which would explain it.
It's a pointer to a GLuint array.
[cpp]GLuint* texRT;[/cpp]
This is how it's initialized:
[cpp]texRT = new GLuint[0];[/cpp]
I'm freeing it like so:
[cpp]RenderTarget::~RenderTarget()
{
printf("- Deleting rendertarget...");
delete[] texRT;
printf("Done.\n");
}[/cpp]
I've got some printfs there to help me out. I get a heap corruption error between those. Am I doing this wrong? I tried doing "&texRT" upon deletion, but that didn't work.[/QUOTE]
I'm assuming you are using Visual Studio for this, so lemme spit some [i]platform specific details[/i] all up in this. (note: Mac OS X, Linux, and friends, may do this, but I don't feel like poking about to see if they do what visual studio does).
[QUOTE=MakeR;37456770]You are allocating 0 bytes of memory? Never mind, apparently passing a pointer to 0 blocks of memory to array delete is fine.[/QUOTE]
This isn't all that true according to the standard. What is ok in C++ is deleting nullptr, so
[cpp]
delete nullptr;
[/cpp]
won't cause the OS to flip its wig.
But what you need to take into account here, is what the MSVC runtime does when you allocate via new[]. Ever notice how you don't have to mention how many items were allocated at an address when you call delete[]? That's because MSVC does a nasty nasty trick. When you call delete[] <address>, what it does is something like this:
[cpp]
void delete[](T* ptr) {
ptrdiff_t actual_start = ptr - sizeof(size_t);
size_t len = *actual_start;
for (auto idx = 0; idx < len; ++idx) {
ptr[idx].~T();
}
free(ptr);
}
[/cpp]
Obviously this is pseudocode, so don't start freaking out about it. Basically, the MSVC runtime stores the number of Ts before the actual address given to you. Now, I'm unsure if it does this for placement new[] and placement delete[], but you should try that out and see what happens. :)
Also, I should briefly note, the standard covers allocating zero length arrays via new[]: [url]http://stackoverflow.com/a/1087066/49000[/url]
And what you should note is this sentence:
[quote=Stackoverflow]
That means you can do it, but you can not legally (in a well defined manner across all platforms) dereference the memory that you get - you can only pass it to array delete - and you should delete it.
[/quote]
So, while [i]you[/i] might not be dereferencing the memory that wasn't technically allocated, the runtime might, and that's where shit is breaking down (see my dereference to actual_start in the pseudocode above). My only suggestion would be to throw a breakpoint on your delete line and step into the debugger to see what is actually happening (so you can avoid stuff like this in the future)
I need some help - somebody give me some Android app ideas :(
Ok so I've got this sort of general problem with my lua framework. GLFW has this call back function.
I've got this callback function for GLFW.
[code]
int GLFWCALL OnWindowCloseCallback() {
// Hook this to lua?
return GL_TRUE;
}
[/code]
How would I get it to call a lua function inside that callback without a lua state? Should I make an event system for it and go through the events in the main loop?
There are any way to tell android to draw triangles without using vertex buffer objects? I want to do that because I do not want to rewrite the model class then to use vertex buffer objects instead of vectors.
[QUOTE=AlienCat;37473141]There are any way to tell android to draw triangles without using vertex buffer objects? I want to do that because I do not want to rewrite the model class then to use vertex buffer objects instead of vectors.[/QUOTE]
IIRC there's still support for vertex arrays, but if you're talking about immediate mode, then no, immediate mode was excluded from the ES specification for a reason, it's going to be several orders of magnitude slower than VBOs (to the point where 10 triangles cost more than a VBO with 1,000 triangles)
Is there any reason that a class function would segfault because it can't access the object it's working on ("this")?
Hey guys.
I'm going to be making a Roguelike soon, and I really haven't had much experience with them in the past (Only experience being my failed attempts at a beginner at programming.) So does anyone have any tips on making a Roguelike?
[QUOTE=ECrownofFire;37476776]Is there any reason that a class function would segfault because it can't access the object it's working on ("this")?[/QUOTE]
[cpp]
#include <iostream>
class Hello
{
int stuff;
public:
void do_stuff()
{
std::cerr << "works!\n";
std::cout << stuff << "\n";
}
};
int main()
{
Hello *hello = NULL;
hello->do_stuff();
return 0;
}
[/cpp]
Edit:
To expand, the reason for this is that non-virtual function calls are resolved at compile time, not runtime. They're the same as plain function calls but with a funky compiler mangled name (i.e: _ZN5Hello8do_stuffEv) and where an implicit this* is passed along. This means that even though we're working on an invalid memory address (NULL in this case) we only find out when the method goes to dereference one of its members.
[QUOTE=qqqqqqqq;37477093]-snip-[/QUOTE]
It's a C++11 shared_ptr that's initialized like this, so it's not that.
[cpp]
std::shared_ptr<Foo> foop(new Foo);
[/cpp]
[editline]30th August 2012[/editline]
And then elsewhere it calls class function using a plain arrow operator, so it's just foop->bar(x, y). GDB says that all three are inaccessible (this, x, and y).
[editline]30th August 2012[/editline]
I can call other class functions just fine from the same location, it's just this one function that fails. GDB says that it just seg-faults as soon as the function enters the stack and "this", x, and y become inaccessible.
[QUOTE=ECrownofFire;37477219]It's a C++11 shared_ptr that's initialized like this, so it's not that.
[cpp]
std::shared_ptr<Foo> foop(new Foo);
[/cpp]
[editline]30th August 2012[/editline]
And then elsewhere it calls class function using a plain arrow operator, so it's just foop->bar(x, y). GDB says that all three are inaccessible (this, x, and y).[/QUOTE]
Post Code.
Generic names because I can.
This is where WTF is called from (WTF is the function I have trouble with). The code of it shouldn't be relevant because none of it executes. It's just a void function that takes int16_t x and int16_t y as arguments and does some stuff with the contents of Class. OtherClass contains a C++11 unordered_map that is a map of type uint32_t, std::shared_ptr<Class>.
[cpp]void OtherClass::SomeFunc(int16_t x, int16_t y, std::shared_ptr<Class> cla) {
chunks.emplace(getHash(x,y), cla); //Get hash is a simple function that returns a "hash" for x and y
std::cout << cla->get(3, 5, 9) << "\n"; //Testing other function in Class, executes just fine
cla->WTF(x, y); //"this", x, and y become inaccessible as soon as this hits the stack.
}[/cpp]
This is the code in the main function where it gets called from (mostly for testing, I'll move it later). Otherp is a regular pointer to an object of OtherClass.
[cpp]
OtherClass* Otherp = new OtherClass("test_otherclass");
std::shared_ptr<Class> classp(new Class);
classp->set(3, 5, 9, 1);
Otherp->setClass(0, 0, classp);[/cpp]
[QUOTE=Killowatt;37476975]Hey guys.
I'm going to be making a Roguelike soon, and I really haven't had much experience with them in the past (Only experience being my failed attempts at a beginner at programming.) So does anyone have any tips on making a Roguelike?[/QUOTE]
[url]http://roguebasin.roguelikedevelopment.org/index.php/Articles[/url]
[QUOTE=Killowatt;37476975]Hey guys.
I'm going to be making a Roguelike soon, and I really haven't had much experience with them in the past (Only experience being my failed attempts at a beginner at programming.) So does anyone have any tips on making a Roguelike?[/QUOTE]
Add dynamic map scrolling asap, later when you will have large codebase it's gonna be huge pain to rewrite
I figured it out, an array was causing the problem.
I'm working with Lua in Minecraft at the moment and I have noticed that when lines of code are executed they are executed in turn rather than simultaneously. What is the technical term for this?
Also, I have this code to make accounts in an accounts table but it doesn't exactly function well. What would be a better way to do this?
[url]http://i.imgur.com/Nu5hd.jpg[/url]
[QUOTE=JakeAM;37482666]I'm working with Lua in Minecraft at the moment and I have noticed that when lines of code are executed they are executed in turn rather than simultaneously. What is the technical term for this?
Also, I have this code to make accounts in an accounts table but it doesn't exactly function well. What would be a better way to do this?
[url]http://i.imgur.com/Nu5hd.jpg[/url][/QUOTE]
What exactly isn't functioning well?
2D collision?
[QUOTE=JakeAM;37482666]when lines of code are executed they are executed in turn rather than simultaneously[/QUOTE]
What
That is the expected behaviour for any computing device, isn't it
[QUOTE=JakeAM;37482666][...] What is the technical term for this?
[...][/QUOTE]
Sequential. Most programs written with a text editor behave this way, as long as they aren't optimized at least.
Minecraft redstone is an example for a non-sequential (parallel) programming language.
[QUOTE=MakeR;37482830]What exactly isn't functioning well?[/QUOTE]
When I try to iterate over the table it gives me the table ids rather than the contents, how do I get it to iterate over the tables and returns the contents?
Another for loop inside that for loop, iterating over pairs(v)
Can someone help me out here?
Im trying to create a rouguelike dungeon using the simple BSP method, for it I have:
[csharp]
public static byte[,] MakeLevel (int pWidth, int pHeight, int pSeed)
{
int depthLevel = 3;
int roomMargin = 1;//Min margin a room has in its rect
int minRoomWidth = 3;
int minRoomHeight = 3;
if (
minRoomWidth + roomMargin + roomMargin > (pWidth / Math.Pow (2, depthLevel)) ||
minRoomHeight + roomMargin + roomMargin > (pHeight / Math.Pow (2, depthLevel))
) {
throw new Exception ("Room too big for width/height");
}
Random rand = new Random (pSeed);
byte[,] dungeon = new byte[pHeight, pWidth];
List<Rectangle> rectList = new List<Rectangle> ();
rectList.Add (new Rectangle (0, 0, pWidth-1, pHeight-1));
List<Rectangle> tempRects = new List<Rectangle> ();
for (int i = 0; i < depthLevel; i++) {
//Subdivide room to max depth
foreach (Rectangle rect in rectList) {
int splitAt = 0;
Rectangle rectA, rectB;
//Splitting th current rect horizontally
if (i % 2 == 0) {
int minSpacing = 0;
for(int a = i; a < depthLevel; a++)
{
minSpacing += roomMargin + roomMargin + minRoomWidth;
}
splitAt = rand.Next (rect.X + minSpacing, rect.X + rect.Width - minSpacing);
rectA = new Rectangle (
rect.X, rect.Y,
splitAt - 1, rect.Height
);
rectB = new Rectangle (
rect.X + splitAt-1, rect.Y,
rect.Width - splitAt + 1, rect.Height
);
} else {
//split current rect vertically
int minSpacing = 0;
for(int a = i; a < depthLevel; a++)
{
minSpacing += roomMargin + roomMargin + minRoomHeight;
}
splitAt = rand.Next (rect.Y + minSpacing, rect.Y + rect.Height - minSpacing);
rectA = new Rectangle (
rect.X, rect.Y,
rect.Width, splitAt - 1
);
rectB = new Rectangle (
rect.X, rect.Y + splitAt-1,
rect.Width, rect.Height - splitAt + 1
);
}
tempRects.Add (rectA);
tempRects.Add (rectB);
}
rectList.Clear ();
rectList.AddRange (tempRects);
tempRects.Clear ();
if (i == depthLevel - 1) {
//in the final depth level create the actual rooms
foreach (Rectangle rect in rectList) {
Rectangle room;
int aX = rand.Next (roomMargin, rect.Width - (roomMargin + minRoomWidth));
int aY = rand.Next (roomMargin, rect.Height - (roomMargin + minRoomHeight));
int aW = rand.Next (minRoomWidth, rect.Width - (roomMargin + roomMargin));
int aH = rand.Next (minRoomHeight, rect.Height - (roomMargin + roomMargin));
room = new Rectangle (aX, aY, aW, aH);
tempRects.Add (room);
}
rectList.Clear ();
rectList.AddRange (tempRects);
tempRects.Clear ();
}
}
for (int y = 0; y < pHeight; y++) {
for (int x = 0; x < pWidth; x++) {
foreach (Rectangle rect in rectList) {
if (rect.Contains (x, y)) {
dungeon [y, x] = 1;
break;
} else
dungeon [y, x] = 0;
}
}
}
return dungeon;
}
[/csharp]
Now assuming my calculations are correct, the splitting stage should always create rects with enought room to hold the room and a padding/wall
the problem is I keep getting, minvalue exceds maxvalue on line 92 as the rects width is negative
So I'm trying to implement a skeletal animation system (and I've already got animations being read out directly from an IQM file), and I'm a bit confused about exactly what a pose's fields are supposed to do. There's a channelOffset array which I feed in as translation, rotation, and scale values (that makes sense), but I don't get why I have to multiply in a scale value based on the mask... Based on the examples that come with the IQM development kit, I wrote up this giant block in C#:
[csharp]if ((pose.Mask & 0x0001) != 0) translation.X += reader.ReadUInt16() * pose.ChannelScale[0];
if ((pose.Mask & 0x0002) != 0) translation.Y += reader.ReadUInt16() * pose.ChannelScale[1];
if ((pose.Mask & 0x0004) != 0) translation.Z += reader.ReadUInt16() * pose.ChannelScale[2];
if ((pose.Mask & 0x0008) != 0) rotation.X += reader.ReadUInt16() * pose.ChannelScale[3];
if ((pose.Mask & 0x0010) != 0) rotation.Y += reader.ReadUInt16() * pose.ChannelScale[4];
if ((pose.Mask & 0x0020) != 0) rotation.Z += reader.ReadUInt16() * pose.ChannelScale[5];
if ((pose.Mask & 0x0040) != 0) rotation.W += reader.ReadUInt16() * pose.ChannelScale[6];
if ((pose.Mask & 0x0080) != 0) scale.X += reader.ReadUInt16() * pose.ChannelScale[7];
if ((pose.Mask & 0x0100) != 0) scale.Y += reader.ReadUInt16() * pose.ChannelScale[8];
if ((pose.Mask & 0x0200) != 0) scale.Z += reader.ReadUInt16() * pose.ChannelScale[9];[/csharp]
Also I'm a bit confused on the distinction between poses and frames. The documentation/example code doesn't really explain it at all, does each pose contain frames or does each frame contain poses? Any help with understanding the IQM format would be helpful (I already have skinning implemented though, and I do have an animated version of mrfixit.iqm in my game, I just want to understand what it all means so that I can write a separate, more abstracted system that I can control better).
What is the best way to store a large number of shorts or bytes that are in a 2D array to a file? Also large means about 4^8 to 4^12.
[QUOTE=Dark7533;37491815]What is the best way to store a large number of shorts or bytes that are in a 2D array to a file? Also large means about 4^8 to 4^12.[/QUOTE]
If the shorts/bytes are random (ie no pattern) the only sane way is to store it as a flat array and write every value after another. If there is a pattern you could compress the data some how, for instance, if it is common for long runs of identical values you could try [url=http://en.wikipedia.org/wiki/Run-length_encoding]Run Length Encoding[/url].
Anyone know how to make collision between a player and a wall?
I'm using c# but any language I use I run into the same problem.
I have 2 squares one is the player and one is supposed to be a wall. I can make it so the player cant go through one side of the square. But I can never make the other sides because it just uses the same if statement in different order.
I was just wondering how to make very basic collision between 2 squares.
if (playerX+playerW >= wallX && playerX <= wallX+wallW && playerY <= wallY+wallH && playerY+playerH >= wallY)
{
playerX = playerX - speed;
}
Sorry, you need to Log In to post a reply to this thread.