[QUOTE=Funley;35081027]In XNA, i have a tilemap. Every tile in it is stored in a list. I need to store the sandpath in a separate list but still have it in the normal tile list. The path pieces have to be ordered in the list so that the first piece in the list is the one next to the green blob (start), the rest ordered on how the path goes and the last is next to the gray square (end). I have no idea how to do this. I added some numbers to the image to simply show how i want the ordered.
[t]http://i.imgur.com/xqyV1.png[/t]
Yes, this is a repost from one week ago, since no one answered it.[/QUOTE]
You could create a linked list with those tiles, each tile get a pointer to the next tile, the end tile get a NULL pointer. So when, your green blob is in a tile, it can check up where is the next tile.
[QUOTE=ROBO_DONUT;35080275]The "TAG_" defines are basically enums. C has enums, but nobody uses them. Preprocessor definitions are pretty much idiomatic. You also see a lot of preprocessor definitions instead of constants and enums and such because preprocessor definitions can be used in some places where constants can't (array sizes are a good example).[/QUOTE]
I understood this part, I've used #defines before, I was a little confused by the hexadecimal notation though.
[QUOTE=ROBO_DONUT;35080275]
tag() and ptr() appear to be 'bitfield'-type manipulations. Values are apparently broken up into a 'tag' part (in the lowest two bits) and a 'ptr' part (using all the rest of the bits). tag() extracts these low bits, while ptr() extracts the rest.
[code]
tag(x):
000000XX
ptr(x):
XXXXXX00
[/code][/QUOTE]
I was guessing it was something like that, once I looked into the bitwise operators, but couldn't understand well until now.
[QUOTE=ROBO_DONUT;35080275]tagptr(p, t) does the reverse process -- it combines a tag and a pointer into a single value using bitwise-OR.
number(x) converts a number to a value by shifting it two places to the left (so that the low bits can be used for a tag).
numval(x) does the reverse -- converts a value to a number by shifting it two places to the right, discarding the two low bits.
intval(x) is the same as numval, but it 'returns' an int instead of a number_t.
builtin(n) converts a value to a number and tags it as TAG_BUILTIN
iscons, issymbol, isnumber, and isbuiltin check a value for the corresponding tag.
This is all pretty standard for C.[/QUOTE]
There is one more thing, though: Those two structures, cons_t and number_t, are completely different, iscons(x) compares the result of calling tag(x) against the CONS tag. I understand getting the lower bits of a number and using it as a tag part, but how would that work if you passed a cons_t structure?
Other than that, thanks for everything.
[QUOTE=Eudoxia;35082820]There is one more thing, though: Those two structures, cons_t and number_t, are completely different, iscons(x) compares the result of calling tag(x) against the CONS tag. I understand getting the lower bits of a number and using it as a tag part, but how would that work if you passed a cons_t structure?[/QUOTE]
I don't know anything about Lisp, so I'm kind of guessing here, but given the use of "ptr" (pointer?), my guess is that value_t can be either an immediate value or a "pointer" to a structure/value (not necessarily an absolute pointer to system memory). So you wouldn't ever call tag() on a cons_t. You'd call it on a value_t to see what type of value it holds.
i.e. If you have a "value_t x" and:
iscons(x) is true, then the value in the upper bits is a [i]pointer[/i] to cons_t
isnumber(x) is true, then the value in the upper bits is a number_t or integer
But this is still speculation based only on the code that you've posted. You'll have to actually look at the rest of the code to see whether that guess is right.
I'm new to Java and OOP in general and so I've resolved to write checkers in an object oriented fashion. I've already written Tic-Tac-Toe and I'm pretty happy with it, but checkers differs in a few areas that force me to reconsider my tactics.
In the Tic-Tac-Toe program, the board was represented by a 2D array of Square enums. Each square had the possible values of Square.EMPTY, Square.X, or Square.O. In checkers this will be an issue as each square may or may not contain a checker which may be either color and may or may not be a king. It seems foolish to stick to such a simplified representation of the board, so I'm considering making the board an array of Square objects, each of which may or may not contain a Checker object, which will be one of two colors (Color.RED or Color.BLACK if I use an enum) and which may or may not be a king. It makes more sense to make these divisions, as each of these components is pretty easy to conceptualize as a separate object, however I feel like I'm just making them separate to make them separate, but then again the entire point of the project is to get better and OOP.
So my question is: are more objects, even if they each serve a very simple purpose, better than one object which takes on too much purpose?
[QUOTE=Rayjingstorm;35083448]I'm new to Java and OOP in general and so I've resolved to write checkers in an object oriented fashion. I've already written Tic-Tac-Toe and I'm pretty happy with it, but checkers differs in a few areas that force me to reconsider my tactics.
In the Tic-Tac-Toe program, the board was represented by a 2D array of Square enums. Each square had the possible values of Square.EMPTY, Square.X, or Square.O. In checkers this will be an issue as each square may or may not contain a checker which may be either color and may or may not be a king. It seems foolish to stick to such a simplified representation of the board, so I'm considering making the board an array of Square objects, each of which may or may not contain a Checker object, which will be one of two colors (Color.RED or Color.BLACK if I use an enum) and which may or may not be a king. It makes more sense to make these divisions, as each of these components is pretty easy to conceptualize as a separate object, however I feel like I'm just making them separate to make them separate, but then again the entire point of the project is to get better and OOP.
So my question is: are more objects, even if they each serve a very simple purpose, better than one object which takes on too much purpose?[/QUOTE]in regard to your last question, I think multiple objects with a simple purpose are more conducive to modularity. Don't take it to an extreme though; segment the tasks into sensible groups that each will be performed by its own object.
Hi,
I'm currently working on a rigid body physics simulation. My problem at the moment is the collision response. There are a few things that bother me:
- Stacking only works for a few boxes (after that, they press into each other, and start sliding away)
- Bodies don't really come to rest (I tried implement some "sleep" condition, but it makes stacking even worse and other areas also become a little less optimal) - I have pretty much solved this for velocity, it's easy to have friction. The problem is the angular velocity, which I don't know how to bring down to complete stop (at the moment bodies don't stop wiggling).
I've been wondering if anyone knows any good articles/tutorials that treat not just basic collision detection/response but ways to improve it.
Regards,
Cabadath
[QUOTE=ROBO_DONUT;35080275]The "TAG_" defines are basically enums. C has enums, but nobody uses them. Preprocessor definitions are pretty much idiomatic. You also see a lot of preprocessor definitions instead of constants and enums and such because preprocessor definitions can be used in some places where constants can't (array sizes are a good example).
tag() and ptr() appear to be 'bitfield'-type manipulations. Values are apparently broken up into a 'tag' part (in the lowest two bits) and a 'ptr' part (using all the rest of the bits). tag() extracts these low bits, while ptr() extracts the rest.
[code]
tag(x):
000000XX
ptr(x):
XXXXXX00
[/code]
tagptr(p, t) does the reverse process -- it combines a tag and a pointer into a single value using bitwise-OR.
number(x) converts a number to a value by shifting it two places to the left (so that the low bits can be used for a tag).
numval(x) does the reverse -- converts a value to a number by shifting it two places to the right, discarding the two low bits.
intval(x) is the same as numval, but it 'returns' an int instead of a number_t.
builtin(n) converts a value to a number and tags it as TAG_BUILTIN
iscons, issymbol, isnumber, and isbuiltin check a value for the corresponding tag.
This is all pretty standard for C.[/QUOTE]
another interesting one to do is NaN-tagging doubles.
this is a great article: [url]http://nikic.github.com/2012/02/02/Pointer-magic-for-efficient-dynamic-value-representations.html[/url]
[QUOTE=ROBO_DONUT;35083248]I don't know anything about Lisp, so I'm kind of guessing here, but given the use of "ptr" (pointer?), my guess is that value_t can be either an immediate value or a "pointer" to a structure/value (not necessarily an absolute pointer to system memory). So you wouldn't ever call tag() on a cons_t. You'd call it on a value_t to see what type of value it holds.
i.e. If you have a "value_t x" and:
iscons(x) is true, then the value in the upper bits is a [i]pointer[/i] to cons_t
isnumber(x) is true, then the value in the upper bits is a number_t or integer
But this is still speculation based only on the code that you've posted. You'll have to actually look at the rest of the code to see whether that guess is right.[/QUOTE]
A "cons" structure is essentially a linked list. The original linked list: the car (Contents of the Address part of Register) are a pointer to a value and the cdr (Contents of the Decrement part of Register) is the pointer to the car of the next cons cell, ie
[IMG]http://upload.wikimedia.org/wikipedia/commons/6/6d/Singly-linked-list.svg[/IMG]
Only instead of holding the value in itself, it holds a pointer to it.
Now, the iscons() thing is mostly applied to value_t structures, but on line 699:
[CODE]while (iscons(cdr_(*pv))) {[/CODE]
Which is weird, because cdr_() returns a cons_t structure. What's even weirder is that pv is a poiter value_t structure.
I guess my main confusion is how these structures are so freely coerced into each other.
[QUOTE=Eudoxia;35085532][CODE]while (iscons(cdr_(*pv))) {[/CODE]
Which is weird, because cdr_() returns a cons_t structure. What's even weirder is that pv is a poiter value_t structure.[/QUOTE]
I'm looking at the source now, and I get why they're able to pack the flags into the two low bits of the pointer -- all of the values have 4-byte alignment, so the last two bits are assumed to be 00, leaving just enough room to pack a 'tag' :D. Pretty crafty.
cdr_(v) is (((cons_t*)ptr(v))->cdr). Which extracts the pointer from v, casts it to a cons_t* (which should be correct, assuming that the value is tagged as a cons), then accesses the 'cdr' field, which is a value_t. So the output of cdr_ is not a cons_t, it is a value_t. Precisely, it is the value_t 'cdr' field of the cons_t structure, so iscons(cdr_(*pv)) is correct. It's dereferencing a pointer as a cons_t and checking whether the cdr field is a pointer to another cons_t.
[QUOTE=Eudoxia;35085532]I guess my main confusion is how these structures are so freely coerced into each other.[/QUOTE]
Well it's all just bits and bytes when you get right down to it. It's how you choose to interpret them that matters, and C gives you complete control in that regard.
[QUOTE=ROBO_DONUT;35086289]I'm looking at the source now, and I get why they're able to pack the flags into the two low bits of the pointer -- all of the values have 4-byte alignment, so the last two bits are assumed to be 00, leaving just enough room to pack a 'tag' :D. Pretty crafty.
cdr_(v) is (((cons_t*)ptr(v))->cdr). Which extracts the pointer from v, casts it to a cons_t* (which should be correct, assuming that the value is tagged as a cons), then accesses the 'cdr' field, which is a value_t. So the output of cdr_ is not a cons_t, it is a value_t. Precisely, it is the value_t 'cdr' field of the cons_t structure, so iscons(cdr_(*pv)) is correct. It's dereferencing a pointer as a cons_t and checking whether the cdr field is a pointer to another cons_t.
Well it's all just bits and bytes when you get right down to it. It's how you choose to interpret them that matters, and C gives you complete control in that regard.[/QUOTE]
Thanks! I think now I can finally read the sources without pulling my hair out, and maybe even hack then a little. Add a type or two. Once I understand how it works I'll be able to make a Lisp that isn't slow as dick. I guess you really do need bit-pushing to do things fast.
Again, thanks dudebro :D
Does anyone know of a CRT screen .fx pixel shader?
[QUOTE=Rayjingstorm;35083448]I'm new to Java and OOP in general and so I've resolved to write checkers in an object oriented fashion. I've already written Tic-Tac-Toe and I'm pretty happy with it, but checkers differs in a few areas that force me to reconsider my tactics.
In the Tic-Tac-Toe program, the board was represented by a 2D array of Square enums. Each square had the possible values of Square.EMPTY, Square.X, or Square.O. In checkers this will be an issue as each square may or may not contain a checker which may be either color and may or may not be a king. It seems foolish to stick to such a simplified representation of the board, so I'm considering making the board an array of Square objects, each of which may or may not contain a Checker object, which will be one of two colors (Color.RED or Color.BLACK if I use an enum) and which may or may not be a king. It makes more sense to make these divisions, as each of these components is pretty easy to conceptualize as a separate object, however I feel like I'm just making them separate to make them separate, but then again the entire point of the project is to get better and OOP.
So my question is: are more objects, even if they each serve a very simple purpose, better than one object which takes on too much purpose?[/QUOTE]
The OO approach would be to make both the board and each individual checker an object.
Your program then asks the board if there are checkers at certain points and to move checkers from square to square.
Your board can then store the checkers however it likes, either as a 2D array of Checker objects all set to null except where they're not or a [url=http://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html]HashMap[/url] using the coordinates as keys. (Either with string concatenation or [url=http://stackoverflow.com/a/677248/823542]a custom defined pair() class because java doesn't bother to provide you with one[/url])
So yes, in OO, the more objects the better. Lay them on with a trowel. If in doubt, abstract the problem further and create more objects.
so i've been doing some sfml / opengl shit on linux because I was going to have a stroke if I continued to try to get it to work with visual studio. problem is now I want to build it on windows. So I assume I did everything correctly as I know have gotten rid of the fucking linker errors and it compiles... but only the command line shows up. No window no nothing. Anyone know what could be up?
[QUOTE=thrawn2787;35098207]so i've been doing some sfml / opengl shit on linux because I was going to have a stroke if I continued to try to get it to work with visual studio. problem is now I want to build it on windows. So I assume I did everything correctly as I know have gotten rid of the fucking linker errors and it compiles... but only the command line shows up. No window no nothing. Anyone know what could be up?[/QUOTE]
Update to SFML 2.0, it's a known error with some graphics cards.
You'll need to change your code a bit, but it should go smoothly.
for some reason my command prompt look like this while debugging:
[url]http://postimage.org/image/upoo3a3d9/[/url]
and then it closes after 10 seconds.
[QUOTE=neos300;35100127]Update to SFML 2.0, it's a known error with some graphics cards.
You'll need to change your code a bit, but it should go smoothly.[/QUOTE]
Thanks to you and some extensive googling to switch to 2.0 it works. I love you.
Found my problem,
im using
[code] if( spell.target is Entity ) [/code] but it always returns false, anyhelp ? :S
Buffer problems in C.
[CODE] char input[255];
int output[255], i;
scanf("%s", input);
for(i=0;i>255;i++);
{
switch(input[i])
{
case 'a':
output[i] = 2;
break;
case 'b':
output[i] = 2;
break;
case 'c':
output[i] = 2;
break;
case 'd':
output[i] = 3;
break;
}
}
for(i=0;i > 255;i++);
{
printf("%02d", output[i]);
}
getch();[/CODE]
It seems to output 0202 if I input "abcd", "ab", "ad" but if I input just d I get "03". I want it so that when I input "abcd" it outputs 2223. What am I doing wrong?
I'm trying to capture each unique tile from this map, but I seem to be hitting a problem.
[img]http://puu.sh/kwve[/img]
On the left is the image I'm trying to process. On the right is a panel full of all the unique tiles I've found. At the bottom right are 2 sets of picturesboxes and labels. The set on the right holds information against the current stored tile that the tile in question is being compared to (stuff like the pixel being compared, where that pixel is, and the color of the pixel) and on the right is the same information for the tile from the image being processed. For some reason, as you can see, I'm getting weird pixels from images that should be the same.
[url=http://pastebin.com/Tb3iYpaB]here[/url] is the entire source, could anyone help me figure out why the two tiles aren't the same? I'll send the project to someone if needed.
[QUOTE=Superbird;35109696]Buffer problems in C.
[CODE] char input[255];
int output[255], i;
scanf("%s", input);
for(i=0;i>255;i++);
{
switch(input[i])
{
case 'a':
output[i] = 2;
break;
case 'b':
output[i] = 2;
break;
case 'c':
output[i] = 2;
break;
case 'd':
output[i] = 3;
break;
}
}
for(i=0;i > 255;i++);
{
printf("%02d", output[i]);
}
getch();[/CODE]
It seems to output 0202 if I input "abcd", "ab", "ad" but if I input just d I get "03". I want it so that when I input "abcd" it outputs 2223. What am I doing wrong?[/QUOTE]
[CODE]for(i=0;i>255;i++);[/CODE]
You're introducing a string. The strings in C ends with the '\0' delimiter. So make this:
[CODE]for(i=0;s[i] != '\0';i++);[/CODE]
Or just invert the ">" to "<" because i = 0 isn't bigger than 255;
[CODE]scanf("%s", input);[/CODE]
To input a string use the function gets() (better)
I think is that '_'
Im having problemns with quadtrees in actionscript.
After a long search, I can't find any in-depth tutorials of how to create one in actionscript.
premade ones exist : [url]http://stackoverflow.com/questions/1991288/quadtree-detects-collision-inaccurately[/url],
but I'd like to create one from scratch, to learn and progress in the language (I dislike copy-pasting code if I dont understand the proscess) I get the theory behind it, just having a hard time thinking how to implement it.
Does anyone know of any good tutorials - for actionscript or have a flowchart/text showing the proscesses involved, thanks
Hi, I want my program to ask for a path and for the user to select the path. Now what would be the easiest way to do this? I write in c++ and in console. I tried with having the user giving the path but ran in to some problems, can I possible use the Win32 GUI to let user browse the path? Or would that just complicate everything?
[QUOTE=landizz;35111921]Hi, I want my program to ask for a path and for the user to select the path. Now what would be the easiest way to do this? I write in c++ and in console. I tried with having the user giving the path but ran in to some problems, can I possible use the Win32 GUI to let user browse the path? Or would that just complicate everything?[/QUOTE]
[url=http://msdn.microsoft.com/en-us/library/windows/desktop/ms646927(v=vs.85).aspx]GetOpenFileName[/url]
[url=http://msdn.microsoft.com/en-us/library/windows/desktop/ms646928(v=vs.85).aspx]GetSaveFileName[/url]
I have some serious issues with my collision checking for my upcoming sidescroller. It's in XNA 4.0 and I am trying to make it work.
Problem illustrated
[img]http://i.imgur.com/2ilzE.png[/img]
[code]using System;
using Microsoft.Xna.Framework;
namespace AutonomianDawn
{
class PhysicsPlayer : PhysicsBase
{
Game1 main;
int direction;
public void Initialize(Game1 main)
{
this.main = main;
}
public void Update()
{
if (main.player.OnGround == false)
{
main.player.Movespeed.Y += GravityForce;
}
if (main.player.Movespeed.Y > MaxFallingspeed)
{
main.player.Movespeed.Y = MaxFallingspeed;
}
CheckTile();
}
public void CheckTile()
{
base.stillOnGround = false;
for (int i = 0; i < main.NulltileList.Count; i++)
{
if (main.player.OnGround == true)
{
Rectangle TestRect = Rectangle.Empty;
TestRect.X = main.player.playerRectangle.X;
TestRect.Y = main.player.playerRectangle.Bottom;
TestRect.Width = main.player.playerRectangle.Width;
TestRect.Height = 16;
if (TestRect.Intersects(main.NulltileList[i].rectangle))
{
base.stillOnGround = true;
}
}
if (main.player.TouchLeft == true)
{
Rectangle TestRect = Rectangle.Empty;
TestRect.X = main.player.playerRectangle.X;
TestRect.Y = main.player.playerRectangle.Bottom;
TestRect.Width = main.player.playerRectangle.Width;
TestRect.Height = 16;
if (TestRect.Intersects(main.NulltileList[i].rectangle))
{
base.stillOnGround = true;
}
}
if (main.player.playerRectangle.Intersects(main.NulltileList[i].rectangle))
{
Vector2 backingVector = main.player.Movespeed;
FixPositon(main.NulltileList[i].rectangle, backingVector);
}
}
if (base.stillOnGround == false)
{
main.player.OnGround = false;
}
else if (stillOnGround == true)
{
main.player.OnGround = true;
}
}
public void FixPositon(Rectangle rectangle, Vector2 backingVector)
{
while (main.player.playerRectangle.Intersects(rectangle))
{
main.player.Position -= backingVector;
main.player.playerRectangle.X = (int)main.player.Position.X;
main.player.playerRectangle.Y = (int)main.player.Position.Y;
}
//CHECK WHICH SIDE COLLISION OCCURS
Rectangle testRectangle = Rectangle.Empty;
testRectangle.Height = 16; //Sets Height of test rectangle
testRectangle.Width = main.player.playerRectangle.Width;
testRectangle.Y = main.player.playerRectangle.Bottom; //Places test rectangle below player
testRectangle.X = main.player.playerRectangle.X; //Aligns the test rectangle's X position to the same of the player rectangle
if (testRectangle.Intersects(rectangle))
{
//TILE IS BELOW PLAYER
main.player.Position.Y = rectangle.Top - main.player.playerRectangle.Height;
main.player.Movespeed.Y = 0;
main.player.playerRectangle.Y = (int)main.player.Position.Y;
main.player.OnGround = true;
}
testRectangle.Y = main.player.playerRectangle.Y - 1;
testRectangle.Height = 16; //Sets Height of test rectangle
testRectangle.Width = main.player.playerRectangle.Width;
testRectangle.Y = main.player.playerRectangle.Top - 1; //Places test rectangle below player
testRectangle.X = main.player.playerRectangle.X;
if (testRectangle.Intersects(rectangle))
{
//TILE IS ABOVE PLAYER
main.player.Position.Y = rectangle.Bottom;
main.player.Movespeed.Y = 0;
main.player.playerRectangle.Y = (int)main.player.Position.Y;
}
testRectangle.X = main.player.playerRectangle.X + main.player.playerRectangle.Width;
testRectangle.Height = main.player.playerRectangle.Height;
if (testRectangle.Intersects(rectangle))
{
//TILE IS TO THE RIGHT OF PLAYER
main.player.Position.X = rectangle.Left - main.player.playerRectangle.Width;
//main.player.Movespeed.X = 0;
main.player.playerRectangle.X = (int)main.player.Position.X;
//main.player.TouchRight = true;
}
testRectangle = Rectangle.Empty;
testRectangle.Height = main.player.playerRectangle.Height; //Sets Height of test rectangle
testRectangle.Width = 16;
testRectangle.Y = main.player.playerRectangle.Y; //Places test rectangle below player
testRectangle.X = main.player.playerRectangle.Left - 13;
if (testRectangle.Intersects(rectangle))
{
//TILE IS TO THE LEFT
main.player.Position.X = rectangle.Right;
//main.player.Movespeed.X = 0;
main.player.playerRectangle.X = (int)main.player.Position.X;
//main.player.TouchLeft = true;
}
testRectangle.Height = 16;
//Check top/bottom
}
}
}
[/code]
Full code of the collision class
check to see if either the player's left side is past the rectangle's right side, or if the player's right side is past the rectangle's left side, if it is, the player has cleared the obstacle and is no longer colliding with it
I just realized a rather strange thing, blocks placed after the game has started do not have this issue, despite being identical to eachother
[editline]13th March 2012[/editline]
So after some testing, I realized that if two blocks exist on the same position, it fixes the issue, this is rather strange
Does anyone know their way round in VBA and specifically VBA for Excel? I want to create a static textbox that displays contents of certain cells. I can't find anywhere how I would write the contents of a range to a textbox, though...
[QUOTE=Tortex;35109420]Found my problem,
im using
[code] if( spell.target is Entity ) [/code] but it always returns false, anyhelp ? :S[/QUOTE]
Does your spell.target's reference inherits the Entity class?
Or is the spell.target null?
I literally have no idea.
It just spits out an error about wrong data type when updateBatch() is called.
[code]
function updateBatch()
tilesetBatch:clear()
for x = 1, tileView - 1 do
for y = 1, tileView - 1 do
tilesetBatch:addq( tileQuads[map.region[x][y]], x * tileSize / 2, y * tileSize / 2 )
end
end
end
[/code]
tilesetBatch:addq( tileQuads[map.region[x][y]], x * tileSize / 2, y * tileSize / 2 )
tileQuads[ map.region[x][y] ] seems to be the fault, but I set it.
[code]
sizeX = 128
sizeY = 128
-- determine land
for x = 1, sizeX do
for y = 1, sizeY do
if ( map.elevation[x][y] >= map.level ) then
map.region[x][y] = 1
else
map.region[x][y] = 0
end
end
end
[/code]
And the quads themselves are established...
[code]
function createTiles( size )
tileQuads = {}
for i = 1, ( tilesetImage:getWidth() / size ) do
tileQuads[i] = love.graphics.newQuad( ( i - 1 ) * size, 0, size, size, tilesetImage:getWidth(), tilesetImage:getHeight() )
end
tilesetBatch = love.graphics.newSpriteBatch( tilesetImage, mapSizeX * mapSizeY )
end
[/code]
I've been staring at this for over an hour, it's probably really obvious.
Sorry, you need to Log In to post a reply to this thread.