[QUOTE=Meatpuppet;33823567]Once I'm done with this c++ book, where should I go? I want to learn how to create a simple 2d game, and I would like to learn how to do use utilizing my c++ knowledge. Any suggestions?[/QUOTE]
Use a 2D graphics library such as SFML. It's very easy to use yet powerful.
[QUOTE=ief014;33823673]Use a 2D graphics library such as SFML. It's very easy to use yet powerful.[/QUOTE]
Thanks a lot dude.
Everytime FModSound gets called it makes annoying lag spike. How can I get rid of it? Sounds are only 8000hz.
[code]
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
DebugMessage("FMOD error!");
exit(-1);
}
}
void FModSound(char *SoundX)
{
FMOD::System *system;
FMOD::Sound *sound1;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
unsigned int version;
result = FMOD::System_Create(&system); ERRCHECK(result);
result = system->getVersion(&version); ERRCHECK(result);
if (version < FMOD_VERSION)
{
DebugMessage("Error! You are using an old version of FMOD");
return;
}
result = system->init(32, FMOD_INIT_NORMAL, 0); ERRCHECK(result);
result = system->createSound(SoundX, FMOD_HARDWARE, 0, &sound1); ERRCHECK(result);
result = system->playSound(FMOD_CHANNEL_FREE, sound1, false, &channel); ERRCHECK(result);
}
[/code]
[QUOTE=rute;33830873]Everytime FModSound gets called it makes annoying lag spike. How can I get rid of it? Sounds are only 8000hz.
[/QUOTE]
It [b]might[/b] have something to do with re-initializing FMOD every time you play a sound...
You should be running everything before createSound only once when your program loads and store the instance returned by System_Create. Then you use that instance to create and play sounds.
[QUOTE=raBBish;33831425]It [b]might[/b] have something to do with re-initializing FMOD every time you play a sound...[/QUOTE]
Yes, thats it. But how I store the instance now?
[code]
// Called at start
void Start(void)
{
FMOD::System *system;
FMOD_RESULT result;
unsigned int version;
result = FMOD::System_Create(&system); ERRCHECK(result);
result = system->getVersion(&version); ERRCHECK(result);
if (version < FMOD_VERSION)
{
DebugMessage("Error! You are using an old version of FMOD.");
return;
}
result = system->init(4, FMOD_INIT_NORMAL, 0); ERRCHECK(result);
}
void FModSound(char *Sound, bool bMusic)
{
FMOD::Sound *sound1;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
if(bMusic)
{result = system->createSound(Sound, FMOD_HARDWARE | FMOD_LOOP_NORMAL | FMOD_2D, 0, &sound1); ERRCHECK(result);}
else
{result = system->createSound(Sound, FMOD_HARDWARE | FMOD_2D, 0, &sound1); ERRCHECK(result);}
result = system->playSound(FMOD_CHANNEL_FREE, sound1, false, &channel); ERRCHECK(result);
}
[/code]
says: "left of '->createStream' must point to class/struct/union/generic type" at createSound.
Is anyone here good with matlab?
I need some way to turn a 1x13 matrix into a 1x1 string.
This is what I have tried:
[code]vara =
65J83Q72KAT94
>> size(vara)
ans =
1 13
>> a = char(vara(:,:))
a =
65J83Q72KAT94
>> size(a)
ans =
1 13
>> a = strcat(vara(:,:))
a =
65J83Q72KAT94
>> size(a)
ans =
1 13
>> a = strcat(vara(:,1),vara(:,2),vara(:,3),vara(:,4),vara(:,5),vara(:,6),vara(:,7),vara(:,8),vara(:,9),vara(:,10),vara(:,11),vara(:,12),vara(:,13))
a =
65J83Q72KAT94
>> size(a)
ans =
1 13[/code]
The only thing I can think of is just outputting all the data into a text file, then using C++ or something to turn it into a 1x1 string, and finally putting it back into matlab.
but that will take a long time as there are 10.000.000 matrixes that need to be converted to strings.
[QUOTE=rute;33831708]Yes, thats it. But how I store the instance now?
says: "left of '->createStream' must point to class/struct/union/generic type" at createSound.[/QUOTE]
Simplest way is storing it in a global. Add an extern in a header file, define it in a code file and set it in Start.
[cpp]// in a header
extern FMOD::System *g_SoundSystem;
// wherever Start is defined
FMod::System *g_SoundSystem;
// inside Start
FMOD::System_Create(&g_SoundSystem);[/cpp]
[code]
#include <stdio.h>
int main( void )
{
char player_name[20];
char player_name_answer[4];
printf( "**********************************************************************\n* *\n* Welcome to TRP *\n* *\n**********************************************************************" );
printf( "\nPlease enter your character's name: " );
scanf( "%s", &player_name );
printf( "Your character's name is: %s , is this correct? (Yes/No): ", player_name );
scanf( "%s", &player_name_answer );
if( player_name_answer == 'Yes' ) {
printf( "Okay your character's name is: %s\n", player_name ); }
if( player_name_answer == 'No' ); {
printf( "Sorry what is your character's name?: " );
scanf( "%s", &player_name ); }
return 0;
}
[/code]
This is my first day ever programming and I can not figure out why this will not work for me, please run it and you'll know whats wrong.
[QUOTE=Proclivitas;33835228][code]
#include <stdio.h>
int main( void )
{
char player_name[20];
char player_name_answer[4];
printf( "**********************************************************************\n* *\n* Welcome to TRP *\n* *\n**********************************************************************" );
printf( "\nPlease enter your character's name: " );
scanf( "%s", &player_name );
printf( "Your character's name is: %s , is this correct? (Yes/No): ", player_name );
scanf( "%s", &player_name_answer );
if( player_name_answer == 'Yes' ) {
printf( "Okay your character's name is: %s\n", player_name ); }
if( player_name_answer == 'No' ); {
printf( "Sorry what is your character's name?: " );
scanf( "%s", &player_name ); }
return 0;
}
[/code]
This is my first day ever programming and I can not figure out why this will not work for me, please run it and you'll know whats wrong.[/QUOTE]
You can't use == to compare strings. You have to include the standard string functions:
[code]#include <string.h>
[/code]
And use strcmp or strncmp to do comparison:
[code]if (!strcmp(player_name_answer, "Yes")
{
blah blah blah blah
}[/code]
[editline]21st December 2011[/editline]
Also note the double quotes - single quotes only go around single char's in C.
If you're wondering why he typed it as if(false), it's because strcmp() returns 0 if the strings are equal.
Ok, I did a memory leak report and here's the report:
[quote]
One instance of "int[]" loaded by "<system class loader>" occupies 408,976 (28.87%) bytes. The memory is accumulated in one instance of "int[]" loaded by "<system class loader>".
Keywords
int[]
[/quote]
However, when fixing this (removing the int[] pixels from the code), the leak still didn't go away. So onto the next report:
[quote]
One instance of "com.ludum.ld22.Screen" loaded by "sun.misc.Launcher$AppClassLoader @ 0x4228538" occupies 377,040 (26.62%) bytes. The memory is accumulated in one instance of "com.ludum.ld22.Screen" loaded by "sun.misc.Launcher$AppClassLoader @ 0x4228538".
Keywords
sun.misc.Launcher$AppClassLoader @ 0x4228538
com.ludum.ld22.Screen
[/quote]
I don't know about this one, I haven't the slightest about what it's saying for me to fix.
There's a couple more but I don't think they really apply to what's going on. Any help please?
I've made substantial knowledge improvements since my last posts :D
[cpp]class ThreeD {
int x, y, z; // coordinates
public:
threeD() { x = y = z = 0; }
threeD(int i, int j, int k) { x = i; y = j; z = k; }
ThreeD operator+(ThreeD op2);
ThreeD operator*(ThreeD op2);
ThreeD operator=(ThreeD op2);
void show();
};[/cpp]
Line 4: error: ISO C++ forbids declaration of 'threeD' with no type
Hmm?
Nevermind I made a fucking rookie mistake
[QUOTE=Meatpuppet;33838702]I've made substantial knowledge improvements since my last posts :D
[cpp]class ThreeD {
int x, y, z; // coordinates
public:
threeD() { x = y = z = 0; }
threeD(int i, int j, int k) { x = i; y = j; z = k; }
ThreeD operator+(ThreeD op2);
ThreeD operator*(ThreeD op2);
ThreeD operator=(ThreeD op2);
void show();
};[/cpp]
Line 4: error: ISO C++ forbids declaration of 'threeD' with no type
Hmm?
Nevermind I made a fucking rookie mistake[/QUOTE]
you need a capital T in line 4 and 5
Fuck yes :D
automerge
[editline]22nd December 2011[/editline]
[QUOTE=Richy19;33838779]you need a capital T in line 4 and 5[/QUOTE]
thus the edit
[editline]22nd December 2011[/editline]
See I said "fuck yes" because I thought that the concept of overloading operators was way over my head when I was reading it, so then I tried to make my own example using that concept (adding, multiplying, dividing 3D coordinates). It all fucking works
I was thinking about writing a language.
I could probably write the compiler, and there are ways to use Common Lisp with the LLVM and even a tutorial on how to implement a language for the LLVM.
But I was just wondering, if the language is to be used for anything (Not that it wouldn't be a toy language), it needs to be able to interact with C and C++ libraries like the GSL and the dreaded Qt in a mostly seamless way. I'm not really an expert, but the LLVM looks more like a compiler than what I think of as a VM. If I wrote a language for it, would it be able to easily call C (and C++) functions, manipulate data and what not? How hard would it be to write a toy language with a little FFI for Qt and other libraries?
I was reading up on sfml, got it to work with code blocks, and started on the tut there. I kind of feel like I'm being rushed into it. Is this normal?
[QUOTE=Eudoxia;33840428]I was thinking about writing a language.
I could probably write the compiler, and there are ways to use Common Lisp with the LLVM and even a tutorial on how to implement a language for the LLVM.
But I was just wondering, if the language is to be used for anything (Not that it wouldn't be a toy language), it needs to be able to interact with C and C++ libraries like the GSL and the dreaded Qt in a mostly seamless way. I'm not really an expert, but the LLVM looks more like a compiler than what I think of as a VM. If I wrote a language for it, would it be able to easily call C (and C++) functions, manipulate data and what not? How hard would it be to write a toy language with a little FFI for Qt and other libraries?[/QUOTE]
The reason they call LLVM a "VM" is that it allows you to target the abstract subset of LLVM IR, which can then be optimized and compiled to assembly for a specific ISA. (Also, hence the low level). For interacting with the ABI of a given language (such as C), you can probably use the clang library. However, I'm unsure if the C bindings actually expose this part of the clang API. (The C++ ABI handling is broken up into GCC/Clang style and MSVC style so you can also interact with them).
So, to answer your question, it wouldn't be too hard to talk to C or C++, the hard part is trying to ensure the bindings you are using work just fine. However, you'll need to be able to easily translate your language to C/C++ types without harm, as well as understand what happens at the low "I'm generating an object file and using LTO" level.
If you're into programming languages (like I am), you might find the challenge of getting it to work right a lot of fun, but you might also end up burning out.
That said, it probably wouldn't hurt to ask the LLVM mailing list. They are extremely accommodating (and overly polite for a mailing list, at least when I asked a question on using LLVM as a VM for games) and can answer any future questions you might have on the subject.
How do you use the SaveToFile and LoadFromFile functions in SFML? More specifically, what file are they talking about?
[editline]22nd December 2011[/editline]
I got it.
[editline]22nd December 2011[/editline]
Where do I find the path environment variable so I don't have to set the build configs every time?
Does anyone know why this gives me the error:
"Unhandled exception at 0x59667a28 in mapeditor.exe: 0xC0000005: Access violation reading location 0x00000019."
[code] void saveFile(map *saveMap)
{
using namespace std;
ofstream file("level_dump.map");
for(int i = 0; i < 50; i++)
{
for(int j = 0; j < 50; j++)
{
file.write(reinterpret_cast<char*>(saveMap->getTile(i,j)->getType()),sizeof(int));
file.write(reinterpret_cast<char*>(saveMap->getTile(i,j)->getPosition().x),sizeof(int));
file.write(reinterpret_cast<char*>(saveMap->getTile(i,j)->getPosition().y),sizeof(int));
}
}
file.close();
}
[/code]
Paint.NET rids my image of transparency and instead replaces it with white.
It's supposed to be white and full transparency, but it's just a white block now.
It's 2048 by 12.
What do I do?
[editline]23rd December 2011[/editline]
Never mind, the save dialog was set to 24-bit instead of auto detect.
I get a segmentation fault when running this project: [url]https://github.com/mastersrp/hacktheplanet[/url]
(it requires this: [url=https://github.com/mastersrp/libscript]libscript[/url] which may cause the segmentation fault, although I'm not sure why)
Im trying to setup a git repo in dropbox, but all i get are errors.
Im following this tutorial: [url]http://tumblr.intranation.com/post/766290743/using-dropbox-git-repository[/url]
And the commands and error are:
[code]
richy@R-Laptop:~/Dropbox$ cd git
richy@R-Laptop:~/Dropbox/git$ mkdir -p Agame.git
richy@R-Laptop:~/Dropbox/git$ cd !$
cd Agame.git
richy@R-Laptop:~/Dropbox/git/Agame.git$ git --bare init
Initialized empty Git repository in /home/richy/Dropbox/git/Agame.git/
richy@R-Laptop:~/Dropbox/git/Agame.git$ git status
fatal: This operation must be run in a work tree
richy@R-Laptop:~/Dropbox/git/Agame.git$ dir
branches config description HEAD hooks info objects refs
richy@R-Laptop:/home$ cd richy/codeblocks/Agame/
richy@R-Laptop:~/codeblocks$ git remote add dropbox file://$HOME/Dropbox/git/Agame.git/
fatal: Not a git repository (or any of the parent directories): .git
[/code]
[QUOTE=Richy19;33853180]Im trying to setup a git repo in dropbox, but all i get are errors.
Im following this tutorial: [url]http://tumblr.intranation.com/post/766290743/using-dropbox-git-repository[/url]
And the commands and error are:
[code]
richy@R-Laptop:~/Dropbox$ cd git
richy@R-Laptop:~/Dropbox/git$ mkdir -p Agame.git
richy@R-Laptop:~/Dropbox/git$ cd !$
cd Agame.git
richy@R-Laptop:~/Dropbox/git/Agame.git$ git --bare init
Initialized empty Git repository in /home/richy/Dropbox/git/Agame.git/
richy@R-Laptop:~/Dropbox/git/Agame.git$ git status
fatal: This operation must be run in a work tree
richy@R-Laptop:~/Dropbox/git/Agame.git$ dir
branches config description HEAD hooks info objects refs
richy@R-Laptop:/home$ cd richy/codeblocks/Agame/
richy@R-Laptop:~/codeblocks$ git remote add dropbox file://$HOME/Dropbox/git/Agame.git/
fatal: Not a git repository (or any of the parent directories): .git
[/code][/QUOTE]
Why not follow the official guides for this instead?
[url]http://book.git-scm.com/4_setting_up_a_private_repository.html[/url]
[url]http://book.git-scm.com/4_setting_up_a_public_repository.html[/url]
This should work fine on dropbox, but I'm not entirely sure.
[cpp] if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::D))
velocityX += .25;
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::A))
velocityX -= .25;
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::W))
velocityY += .25;
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::S))
velocityY -= .25;
[/cpp]
Is there any substitute for this? I tried using if(App.GetInput().IsKeyDown(sf::Key::(key)), but I have no idea how to use that without it acting stupidly to key presses (as in, 1 key press equals many instances of the if.). if there isn't, how can I make it register two keys being pressed at once (I tried the obvious, you have to press them at the exact same time for it to work).
[QUOTE=Meatpuppet;33855840][cpp] if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::D))
velocityX += .25;
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::A))
velocityX -= .25;
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::W))
velocityY += .25;
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::S))
velocityY -= .25;
[/cpp]
Is there any substitute for this? I tried using if(App.GetInput().IsKeyDown(sf::Key::(key)), but I have no idea how to use that without it acting stupidly to key presses (as in, 1 key press equals many instances of the if.). if there isn't, how can I make it register two keys being pressed at once (I tried the obvious, you have to press them at the exact same time for it to work).[/QUOTE]
You [i]could[/i] use a map between keys and amounts to add to the velocity, but it'd be a lot more code and frankly what you've got there is fine.
You just have to make sure that doesn't grow into an unwieldy mess if you ever add stuff to it.
[QUOTE=Meatpuppet;33855840][cpp] if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::D))
velocityX += .25;
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::A))
velocityX -= .25;
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::W))
velocityY += .25;
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::S))
velocityY -= .25;
[/cpp][/QUOTE]
Not an answer to your question directly, but you should consider using this format for events:
[cpp]
sf::Event event;
switch(event.Type)
{
case sf::Event::KeyPressed :
if(event.Key.Code == sf::Key::D)
{
velocityX += 0.25;
}
else if (...) etc...
break;
}
[/cpp]
[QUOTE=Meatpuppet;33855840]
I have no idea how to use that without it acting stupidly to key presses (as in, 1 key press equals many instances of the if.).
[/QUOTE]
The reason for this is because SFML keeps track of which keys are being currently held down. If you use this in some sort of "Tick" functions that is repeatedly called, it will check if that key is currently held down.
If you want to do a check if two keys are being pressed and only call the function of the combo once, try something like:
[cpp]
sf::Event event;
switch(event.Type)
{
case sf::Event::KeyPressed :
//A + D key combo
if(event.Key.Code == sf::Key::D)
{
if(App.GetInput().IsKeyDown(sf::Key::A))
{
//code when keys D and A are pressed
}
}
// We need to do this both ways.
// You probably want to make the combo call a method to perform the key combo function to refrain from writing code twice
if(event.Key.Code == sf::Key::A)
{
if(App.GetInput().IsKeyDown(sf::Key::D))
{
//code when keys D and A are pressed
}
}
break;
}
[/cpp]
There's a reason why you should do it both ways, and I can explain if you need me to
-Eventually figured it out-
[QUOTE=FPSMango;33850747]Does anyone know why this gives me the error:
"Unhandled exception at 0x59667a28 in mapeditor.exe: 0xC0000005: Access violation reading location 0x00000019."
[code] void saveFile(map *saveMap)
{
using namespace std;
ofstream file("level_dump.map");
for(int i = 0; i < 50; i++)
{
for(int j = 0; j < 50; j++)
{
file.write(reinterpret_cast<char*>(saveMap->getTile(i,j)->getType()),sizeof(int));
file.write(reinterpret_cast<char*>(saveMap->getTile(i,j)->getPosition().x),sizeof(int));
file.write(reinterpret_cast<char*>(saveMap->getTile(i,j)->getPosition().y),sizeof(int));
}
}
file.close();
}
[/code][/QUOTE]
I'm guessing that you want the reinterpret cast to convert numbers to strings, but this is not what it does. What your code is doing is "pretend this int is a pointer to a memory location and pass it to write" and then write crashes when it tries to read the invalid memory location represented by the tile's "type" value of 0x19.
If you're trying to save the numbers in a human readable text format, you can use ofstream's << operator.
[cpp]
file << value << ' '; // dont forget to separate the fields
// instead of
file.write(value);
[/cpp]
[editline]23rd December 2011[/editline]
[QUOTE=vexx21322;33859217]I've never done this before, so I need some help with what to do.
I want to use the windows 7 api code pack for something in one of my projects. The zip contains a bunch of binaries that I'm guessing I need to place somewhere to use. Problem is, I have no clue where to place them, and google search isn't helping me.[/QUOTE]
What is it you are trying to do with the api code pack? The question you asked isn't the question you need help solving.
[QUOTE=Meatpuppet;33855840]keyboard stuff[/QUOTE]
What ief014 said. The way I do it is to have two arrays, game_kb and game_kb_old, which hold snapshots of every key that's pressed in a frame. game_kb polls the keyboard every frame, then at the end of that frame game_kb_old is made a copy of game_kb, so between those two events I check them like this:
-A key is down if it exists in game_kb
-A key has just been pressed once ('not pressed' to 'pressed') if game_kb holds it but game_kb_old doesn't
-A key has just been released if game_kb_old holds it but game_kb doesn't
Combos can be checked something like this (pseudo):
[code]
vector<int> keys = { sf::Keyboard::A, sf::Keyboard::D };
...
bool combo = true;
for(size_t i = 0; i < keys.size(); i++)
{
if(!game_kb.contains(keys[i]))
{
combo = false;
break;
}
}
if(combo)
//do combo move
[/code]
This does kind of duplicate sf::Event polling stuff, but it's easier for me this way.
[QUOTE=Richy19;33853180]Im trying to setup a git repo in dropbox, but all i get are errors.
Im following this tutorial: [url]http://tumblr.intranation.com/post/766290743/using-dropbox-git-repository[/url]
And the commands and error are:
[code]
richy@R-Laptop:~/Dropbox$ cd git
richy@R-Laptop:~/Dropbox/git$ mkdir -p Agame.git
richy@R-Laptop:~/Dropbox/git$ cd !$
cd Agame.git
richy@R-Laptop:~/Dropbox/git/Agame.git$ git --bare init
Initialized empty Git repository in /home/richy/Dropbox/git/Agame.git/
richy@R-Laptop:~/Dropbox/git/Agame.git$ git status
fatal: This operation must be run in a work tree
richy@R-Laptop:~/Dropbox/git/Agame.git$ dir
branches config description HEAD hooks info objects refs
richy@R-Laptop:/home$ cd richy/codeblocks/Agame/
richy@R-Laptop:~/codeblocks$ git remote add dropbox file://$HOME/Dropbox/git/Agame.git/
fatal: Not a git repository (or any of the parent directories): .git
[/code][/QUOTE]
You've initialized the current directory as the actual repository. Typically the git files sit in the .git subdirectory, but with --bare it uses the current directory. Don't use bare.
Sorry, you need to Log In to post a reply to this thread.