[QUOTE=commander204;27266017]I am trying to make my own game in XNA but am stuck at the map loading. I want to have an xml file with the map class in it. Only I can't get the list to work.(A list of tiles actually!)[/QUOTE]
Try google..
[code]
XmlTextReader reader = new XmlTextReader(Link or path);
while (reader.Read())
{
if (reader.Name == "name")
{
the node name is "name"
reader.read();
reader.value is the value of the node
[/code]
[QUOTE=yakahughes;27265902]Ah. How are you implementing tables? I assume you can store whatever type of data you want in one.[/QUOTE]
On the state level it's handled like so:
[cpp]
// Bragi is the interpreter class
Variable::Variable( Bragi* Par, TYPE Type) {
Par->Garbage( this ); // Mark for garbage collection
Parent = Par;
this->Type = Type;
References = 0;
if( Type == TYPE::TTABLE ) {
Val.t.HighestNumerical = 0;
Val.t.VariableCount = 0;
Val.t.Vars = (TableIndex*)malloc(sizeof(TableIndex)*128);
for (int i = 0; i < 128; i++ ) {
Val.t.Vars[i].Key = 0;
Val.t.Vars[i].Value = 0;
}
}
// Other TYPE handlers go here
}
[/cpp]
Accessing and inserting data is handled like so:
[cpp]
bool Variable::SetMember( Variable* Idx, Variable* Value ) {
if( Type != TTABLE ) { return false; }
// If the index is nil, just add it to the end of the numerical indices
if( Idx->IsNil() ) {
Idx->Unreference();
Idx = new Variable( Parent, (float)Val.t.HighestNumerical+1 );
}
// Check if the index is an integer, and is bigger than the highest index, if it is, make it the highest.
if( Idx->IsNumber() ) {
if( fmod( Idx->GetNumber(), 1 ) == 0 && Idx->GetNumber() > Val.t.HighestNumerical ) {
Val.t.HighestNumerical = (int)Idx->GetNumber();
}
}
Val.t.Vars[Val.t.VariableCount].Key = Idx;
Val.t.Vars[Val.t.VariableCount].Value = Value;
Val.t.VariableCount++;
Idx->Reference();
Value->Reference();
return true;
}
Variable* Variable::GetMember( Variable* Idx ) const {
for( int i = 0; i < Val.t.VariableCount; i++ ) {
if( *Idx == *(Val.t.Vars[i].Key) ) {
Val.t.Vars[i].Value->Reference();
return Val.t.Vars[i].Value;
}
}
return new Variable( Parent ); // "nil"
}
[/cpp]
In the interpreter:
[cpp]
case BYTECODE::NEWTABLE:
{
Push( new Variable( this, TYPE::TTABLE ) );
break;
}
case BYTECODE::SETFIELD:
{
Variable* Val = GetVariable( -1 );
Variable* Key = GetVariable( -2 );
Variable* Tbl = GetVariable( -3 );
Pop( 2 );
Tbl->SetMember( Key, Val );
Key->Unreference();
Val->Unreference();
Tbl->Unreference();
break;
}
case BYTECODE::GETFIELD:
{
Variable* Key = GetVariable( -1 );
Variable* Tbl = GetVariable( -2 );
Pop( 2 );
Push( Tbl->GetMember( Key ) );
Key->Unreference();
Tbl->Unreference();
break;
}
[/cpp]
On the compiler level:
[code]
Table = { First = "Hello ", Second = "World!" }
[/code]
Is converted to this: (Indention is just to make it easier to understand)
[code]
PUSHSTRING "Table"
NEWTABLE
PUSHSTRING "First"
PUSHSTRING "Hello"
SETFIELD
PUSHSTRING "Second"
PUSHSTRING "World!"
SETFIELD
SETVAR
[/code]
Or if you executed the above code with debug enabled:
[img]http://i.cubeupload.com/t1cxC6.png[/img]
[QUOTE=Dr Magnusson;27266318]On the state level it's handled like so:
[i]informative[/i][/QUOTE]
Ah, so it's a linear search. I was thinking you were doing it hashtable style.
Hey guys, I could use a little advice.
Currently in my game engine, colors, vectors, and really any data that's a group of ordered numbers, are all contained in arrays. I came up with this because I can't return 3 floating point numbers, for instance, and I'd rather not have wrapper classes for such simple data.
An example:
[code]
int[] pos = new int[2];
float[] color = new float[3];[/code]
pos[0] is x and pos[1] is y.
color[0] is r, color[1] is g, and color[2] is b.
As it is, it works very fast and I can do complicated math easily, without having dependencies on a class like Vector2i or Color3f.
Should I leave it as it is or wrap the fields into a class or what?
[QUOTE=Smashmaster;27266489]Hey guys, I could use a little advice.
Currently in my game engine, colors, vectors, and really any data that's a group of ordered numbers, are all contained in arrays. I came up with this because I can't return 3 floating point numbers, for instance, and I'd rather not have wrapper classes for such simple data.
An example:
[code]
int[] pos = new int[2];
float[] color = new float[3];[/code]
pos[0] is x and pos[1] is y.
color[0] is r, color[1] is g, and color[2] is b.
As it is, it works very fast and I can do complicated math easily, without having dependencies on a class like Vector2i or Color3f.
Should I leave it as it is or wrap the fields into a class or what?[/QUOTE]
If you had a struct, such as:
[cpp]
struct Color {
int r;
int b;
int g;
};[/cpp]
It would be, in memory, the exact same as an array of 3 ints. So it won't be any different, except a class is simpler and more understandable to use (clr.g instead of clr[2]) and is neater in my opinion.
[editline]7th January 2011[/editline]
Oh, is that Java? Forget that then.
[QUOTE=PiXeN;27265591]I'm 16, 1 year and a half before I leave highschool, and I haven't had a single programming class in any of the schools I was.
Consider yourself lucky.[/QUOTE]
Not really lucky, since the teacher seems to not know much, but I think he does.
I feel bad for him, he's a pretty nice guy, and everyone is so stupid that he gets frustrated a lot.
I think there's a Java programming class too, joy.
[QUOTE=yakahughes;27266457]Ah, so it's a linear search. I was thinking you were doing it hashtable style.[/QUOTE]
I just wanted to see if I could get it to work at all. The current table management is a little.. Odd, just look at the highest numerical thing. I'm gonna rewrite it.
[QUOTE=The Inzuki;27266614]Not really lucky, since the teacher seems to not know much, but I think he does.
I feel bad for him, he's a pretty nice guy, and everyone is so stupid that he gets frustrated a lot.
I think there's a Java programming class too, joy.[/QUOTE]
I formed / host a programming club at my school. We break into (basically the IT Staff let us in) to a computer room and we spend 2 lunches a week looking at code. I tend to be the one they lean on, and believe me, it's great.
Despite there blatant box-ines, I like helping them. I have thought of a career in teaching computer programming to students and it seems like a viable career choice. When they ask you dumb questions like "How do I get a console to write a line of text?" Point them in the right direction.
For instance, today I was asked how I could get a ship to travel in a relevant direction. A very good question I thought, considering he'd only been coming for 3 months. I gave him a Wiki to Trigonometry and provided some pseudo code. That's all you have to do. Just be polite and force them to learn stuff themselves.
The worst time is when you're pissed about something. Just provide a wiki or some quick advice and leave it at that. Flipping at someone will make them move away from programming.
I'm thinking of writing a scripting language in C#, how does dorëshkrim sound as a name? (Albanian for manuscript)
[QUOTE=ZenX2;27266996]I'm thinking of writing a scripting language in C#, how does dorëshkrim sound as a name? (Albanian for manuscript)[/QUOTE]
If you don't expect anyone to say it or write it or read it, yeah it's good.
What about shkrim? (writing)
I want to see if I can take the best parts of lua and ruby, and make them my own :downs:
[QUOTE=Layley;27265695]How do large scale games update themselves without having to download the entire game again?[/QUOTE]
Most of the stuff you download when you download a game is content, libraries, etc.. So they could recompile the game and update the executable with relative ease.
Also, while I haven't had a lot of experience with dynamically linked libraries and to be honest I'm not quite sure how they work, but some games/engines like Source use .dll's to handle a lot of important stuff, so they can ship those out easily as well.
[editline]7th January 2011[/editline]
[QUOTE=ZenX2;27266996]I'm thinking of writing a scripting language in C#, how does dorëshkrim sound as a name? (Albanian for manuscript)[/QUOTE]
Why not throw in some Russian characters for style, nobody is going to be typing the name out anyway. :v:
[QUOTE=ZenX2;27267125]What about shkrim? (writing)
I want to see if I can take the best parts of lua and ruby, and make them my own :downs:[/QUOTE]
Name it Luaby.
Or Rua.
[QUOTE=Dlaor-guy;27267674]Name it Luaby.
Or Rua.[/QUOTE]
Rubeus.
C# sounds like the more sensible option, but I have an itching to write it in lua...
[editline]7th January 2011[/editline]
SHIT, earthquake here in california
[editline]7th January 2011[/editline]
I'm still shaking
Starting a platform engine, using SFML.
:siren: Nothing special at all! :siren:
I may make a simple game out of this, but it won't be released.
Learners gonna learn.
[media]http://grab.by/grabs/26182bd4c7bc4da5501cf66c9cce67b62c80526a3a.png[/media]
Wow, only a 2.6.
Yet it made cracks in my house.
[QUOTE=ZenX2;27267125]What about shkrim? (writing)
I want to see if I can take the best parts of lua and ruby, and make them my own :downs:[/QUOTE]
Shkrim sounds awesome.
Made this with SFML2 and FMOD:
[IMG]http://i52.tinypic.com/2i7t6e.jpg[/IMG]
[url]http://filesmelt.com/dl/derp2.rar[/url]
Drag and drop a music file on the executable to play it, or just run it and chill.
[code][cpp]#include <algorithm>
#include <vector>
#include <fmod.hpp>
#include <SFML/Graphics.hpp>
#ifdef _WIN32
#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
#endif
class Oscilloscope: public sf::Drawable
{
private:
typedef float FPType;
typedef std::vector<FPType> vector;
FMOD::Channel* myChannel;
int myNumSamples; // spectrum window to sample
vector mySpectrumL, mySpectrumR; // current (interpolated) spectrum values
vector mySpectrumLastL, mySpectrumLastR; // previous values we're interpolating from
vector mySpectrumTargetL, mySpectrumTargetR; // current target
size_t myRangeMin, myRangeMax; // index range for spectrum plotting
bool myInterpolate, myNormalise, myIsPlaying, myIsPaused;
double myAdaptMinL, myAdaptMinR, myAdaptMaxL, myAdaptMaxR; // adaptive normalisation values
sf::Vector2f myDispSize; // screen display size
double myUpdateInterval, myUpdateTimer; // timing
float* myBuf; // temporary buffer for updates
FMOD_DSP_FFT_WINDOW myFFTWindow; // FMOD FFT window algorithm to use
// sigmoid function
static inline double sigmoid(double x)
{
return (1 / (1 + exp(-x))) - 0.5;
}
// volume normalisation routine
template<typename Tvec>
static void normaliseVector(Tvec& target, double& minVal, double& maxVal)
{
minVal = std::min(minVal, double(*std::min_element(target.begin(), target.end())));
maxVal = std::max(maxVal, double(*std::max_element(target.begin(), target.end())));
typedef Tvec::value_type T;
std::transform(target.begin(), target.end(), target.begin(),
[minVal, maxVal](T val) -> T {
return T((val - minVal) / (maxVal - minVal));
});
}
// interpolates two vectors (source and target) against a ratio
template<typename Tvec>
static void interpolateVectors(Tvec& source, Tvec& target, Tvec& result,
double ratio)
{
typedef Tvec::value_type T;
std::transform(source.begin(), source.end(), target.begin(), result.begin(),
[ratio](T start, T target) -> T {
if (start == target) return target;
return T((start * (1-ratio)) + (target * ratio));
});
}
// initialise the vectors and memory buffer
void initialise()
{
if (!myChannel)
return;
size_t nSamples = myRangeMax - myRangeMin;
mySpectrumL.resize(nSamples);
mySpectrumR.resize(nSamples);
mySpectrumLastL.resize(nSamples);
mySpectrumLastR.resize(nSamples);
mySpectrumTargetL.resize(nSamples);
mySpectrumTargetR.resize(nSamples);
if (myBuf)
delete myBuf;
myBuf = new float[myNumSamples];
}
// retrieve spectrum data for given channel
void getChannelData(int ichannel, vector& target)
{
if (myChannel)
{
myChannel->getSpectrum(myBuf, myNumSamples, ichannel, myFFTWindow);
if (myInterpolate)
std::copy(myBuf+myRangeMin, myBuf+myRangeMax-1, target.begin());
else
std::copy(myBuf+myRangeMin, myBuf+myRangeMax-1, target.begin());
}
}
public:
Oscilloscope(FMOD::Channel* channel, size_t samples = 64,
FMOD_DSP_FFT_WINDOW mode = FMOD_DSP_FFT_WINDOW_RECT,
size_t rangeMin = 0, size_t rangeMax = 0)
: myChannel(channel),
myNumSamples(samples),
mySpectrumL(),
mySpectrumR(),
mySpectrumTargetL(),
mySpectrumTargetR(),
mySpectrumLastL(),
mySpectrumLastR(),
myFFTWindow(mode),
myDispSize(sf::Vector2f(200,100)),
myRangeMin(rangeMin),
myRangeMax(rangeMax > 0 ? rangeMax : samples),
myInterpolate(true), myNormalise(false),
myAdaptMaxL(0.00001), myAdaptMaxR(0),
myAdaptMinL(0), myAdaptMinR(0), myBuf(0),
myUpdateInterval(60/1000.0), // update the spectrum every 60ms
myUpdateTimer(myUpdateInterval)
{
initialise();
}
~Oscilloscope()
{
if (myBuf)
delete myBuf;
}
FMOD::Channel* GetChannel() const { return myChannel; }
void SetChannel(FMOD::Channel* channel) { myChannel = channel; }
void SetInterpolate(bool value) { myInterpolate = value; }
bool Interpolate() const { return myInterpolate; }
void SetNormalise(bool value) { myNormalise = value; }
bool Normalise() const { return myNormalise; }
void SetRange(sf::Vector2i range) { SetRange(range.x, range.y); }
void SetRange(int min, int max)
{
if (min < 0) min = 0;
if (max > myNumSamples) max = myNumSamples;
myRangeMin = min;
myRangeMax = max;
initialise();
}
sf::Vector2i GetRange() { return sf::Vector2i(myRangeMin, myRangeMax); }
void SetSize(sf::Vector2f size) { myDispSize = size; }
void SetSize(float width, float height)
{
myDispSize = sf::Vector2f(width, height);
}
sf::Vector2f GetSize() const { return myDispSize; }
void Update(double frameTime)
{
if (myChannel)
{
myChannel->isPlaying(&myIsPlaying); myChannel->getPaused(&myIsPaused);
if (!myIsPlaying || myIsPaused) return;
myUpdateTimer += frameTime;
if (myUpdateTimer >= myUpdateInterval)
{
myUpdateTimer -= myUpdateInterval;
getChannelData(0, mySpectrumTargetL);
getChannelData(1, mySpectrumTargetR);
if (myNormalise)
{
normaliseVector(mySpectrumTargetL, myAdaptMinL, myAdaptMaxL);
normaliseVector(mySpectrumTargetR, myAdaptMinR, myAdaptMaxR);
myAdaptMaxL *= 0.9; myAdaptMaxR *= 0.9;
}
}
if (myInterpolate)
{
std::copy(mySpectrumL.begin(), mySpectrumL.end(), mySpectrumLastL.begin());
std::copy(mySpectrumR.begin(), mySpectrumR.end(), mySpectrumLastR.begin());
// Apply linear interpolation
double ratio = frameTime / myUpdateInterval;
interpolateVectors(mySpectrumLastL, mySpectrumTargetL, mySpectrumL, ratio);
interpolateVectors(mySpectrumLastR, mySpectrumTargetR, mySpectrumR, ratio);
}
}
}
private:
void RenderOscilloscope(sf::Renderer& r,
const vector& dataL,
const vector& dataR,
const sf::Vector2f& size,
const sf::Color& colourLeft,
const sf::Color& colourRight) const
{
using namespace sf;
double x = 0;
double step = (myDispSize.x / dataL.size());
double halfWidth = size.x / 2.0, halfHeight = size.y / 2.0;
r.PushStates();
r.Begin(Renderer::TriangleStrip);
for (unsigned int i=0; i<dataL.size(); i++)
{
double valL = (sigmoid(dataL[i]*10) * 2.0) + 0.005;
double valR = (sigmoid(dataR[i]*10) * 2.0) + 0.005;
r.AddVertex(x + step/2, (valL * -halfHeight) + halfHeight, 0, 0, colourLeft);
r.AddVertex(x + step/2, (valR * halfHeight) + halfHeight, 0, 0, colourRight);
x += step;
};
r.End();
r.PopStates();
}
void Render(sf::RenderTarget& rt, sf::Renderer& r) const
{
if (myInterpolate)
RenderOscilloscope(r, mySpectrumL, mySpectrumR, myDispSize, sf::Color::Yellow, sf::Color::Red);
else
RenderOscilloscope(r, mySpectrumTargetL, mySpectrumTargetR, myDispSize, sf::Color::Yellow, sf::Color::Red);
}
};[/cpp][/code]
[QUOTE=Loli;27263903]I was more sort of hoping for something that can check who is connected. From what I have read this simply gathers data. I just want to know when somebody (Who isn't in my "Trusted IP" list) connects to my router. This could come in useful for when people decide to do port scans...[/QUOTE]
What you COULD do, is check a range of IP's. Like usually, there's configured an IP range from like *.100 to *.250 or something like that. Then just send out a few threads like the Angry IP scanner does, except don't scan ports or anything, just get the hostname, and if it's dead or alive (and then filter away the dead ones). I'm not sure if you can get the MAC address of a PC, but once you've got the IP's and the hostnames, you can start making a whitelist. Of course, If someone trusted has both hostname and IP and possible the same MAC address (can be hacked), then you can't really tell the difference. But something like this could even be written with the standard Python 3.1 libs.
[QUOTE=ZenX2;27268097]Yet it made cracks in my house.[/QUOTE]
:ohdear:
[QUOTE=Loli;27261020]Computer Science - More low level sort of stuff
Software Engineering - More based around applications development and design patters etc.[/QUOTE]
Computer science is algorithms, data structures, language design, that sort of thing. It's the research field that produces concepts like the linked list, [url=http://en.wikipedia.org/wiki/Backus–Naur_Form]BNF[/url], and [url=http://en.wikipedia.org/wiki/Dijkstra's_algorithm]Djikstra's algorithm[/url].
Software engineering is applying computer-science principles to build actual useful programs. Modularity, maintainability, and efficiency are major concerns. Computer science often provides multiple tools that [i]can[/i] be used for a particular purpose (e.g. array vs. linked list), but one or the other will be more appropriate based on engineering concerns (e.g. expected pattern of access, memory constraints).
Think of the difference between physics (discovering Newton's laws) and mechanical engineering (designing machines).
Well I found the reason for the cracks.
[b]Earlier[/b] there was 2.9, just now there was 4.1! :ohdear:
[QUOTE=Loli;27263903]I just want to know when somebody (Who isn't in my "Trusted IP" list) connects to my router. This could come in useful for when people decide to do port scans...[/QUOTE]
Port scans typically don't involve establishing connections. You could check the source IP of every packet, but you'd have to filter out packets corresponding to connections that [i]you[/i] initiated, so that you don't get alarms for every random webserver you make an HTTP connection to. And there's enough "background noise" on the net that you'd probably get more alerts than you expect anyway.
You might want to look into [url=http://www.snort.org/]Snort[/url], which looks for actual suspicious activity rather than just unrecognized IP addresses.
Working on another Android game, got the physics started
[img]http://gyazo.com/1c8eafc9c38a01727f58a8d40178c578.png[/img]
new video of a couple new features :D
[media]http://www.youtube.com/watch?v=YhV1oeAzb_M[/media]
Completelly dropped my laptop, thought it was a goner.
So far it seems ok apart from having dust all over the screenm :v:
My game engine now has texturing. Walls/obstacles have black outlines.
[img]http://img513.imageshack.us/img513/5914/screenshottexturing.jpg[/img]
For those that didn't see the engine from the last thread:
[url]http://www.facepunch.com/threads/1028402-What-are-you-working-on-V14?p=27055558&highlight=#post27055558[/url]
EDIT: A roadblock I've run into is that lighting that hits a wall from one side will light the other side. I don't know how to fix this besides subdividing tiles into 4 or 9 lighting tiles.
Quick question:
In C++, what is the easiest way to store, in an individual header file, the list of tile types in the game? Each tile type would have to have a tile ID, tile name (c string), it's X offset in the tileset image, it's Y offset, it's width, and its height.
More specifically, what is the syntax to do this? I don't want to be allocating an array with this information at runtime, so it needs to be static.
[editline]8th January 2011[/editline]
It would also have to store it's RGB color value (either as an integer, 3 chars, or an sf::Color if possible) of it's reference pixel in the level image. As in, here's what the level looks like:
[img]http://i.imgur.com/Ta2Gt.png[/img]
So it needs to store what color value of pixels in the level image should be a specific tile.
[QUOTE=foszor;27269076]Working on another Android game, got the physics started
[img_thumb]http://gyazo.com/1c8eafc9c38a01727f58a8d40178c578.png[/img_thumb][/QUOTE]
Which physics engine are you using?
[QUOTE=Robber;27269677]Which physics engine are you using?[/QUOTE]
Using a game engine that uses Box2D. [url]http://www.andengine.org/[/url]
Sorry, you need to Log In to post a reply to this thread.