C/C++ Programming Help Thread
This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Zitat von -PSPJunkie- You need to make you image variable global. So define the image in a ".h" file and ...
-
06-14-2007, 07:11 PM #5041QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
Does that mean i would put,
Zitat von -PSPJunkie-
in Game.h?Code:extern Image* zombiepic;
I also have
that is defined in enemyAI.c which i would like it to be "seen" by game.c.Code:zombie[0].x; zombie[0].y;
would i put the two in enemyAI.h as
?Code:extern int zombie[0].x; extern int zombie[0].y;
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
06-14-2007, 07:47 PM #5042
okay here is what you do.
game.h:
game.c:Code:extern Image *zombiepic; extern int zombie[0].x; extern int zombie[0].y;
enemyAI.c:Code:Image *zombiepic;
and have all the .c files #include "game.h" and have all the files in the makefile. What "extern" does is it says that Image *zombiepic was defined but in a different location which is in game.cCode:int zombie[0].x; int zombie[0].y;
Current releases:
Icon Action Replacer v1.5- latest release
Current projects:
PSP C++ IDE - Currently v1.6
RPG Paradise - Latest version at my website
-
06-14-2007, 08:04 PM #5043Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
the first part is right, but the zombie part is not. instead of doing this:
Zitat von BlackShark
you should make the whole zombie external:Code:extern int zombie[0].x; extern int zombie[0].y;
something like that.Code:extern Zombie zombie[NUM_ZOMBIES];
and pspballer, why are are defining the image twice in two files? you post make no sense. could you re-explain please?--------------------------------------------------------------------------------------
-
06-14-2007, 08:27 PM #5044Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
Zitat von Altimax
Code:void readDir(char* directory) { int z; SceUID dir = sceIoDopen(directory); if(dir > 0) { SceIoDirent folder; memset(&folder, 0, sizeof(SceIoDirent)); while(sceIoDread(dir, &folder) > 0){//if there is still something in folder printf("%s\n",folder.d_name); z+=8;//text height if(z > 272) break;//screen height } sceIoDclose(dir); } } int main() { pspDebugScreenInit(); SetupCallbacks(); readDir("ms0:/PSP/GAME/"); sceKernelSleepThread(); return 0; }
-
06-14-2007, 08:28 PM #5045
When you use 'extern', it only means that the var exists somewhere, so you have to declare the "real" var in a C file. There is an article about this somewhere but my internet can't stay connected
Zitat von Grimfate126
Current releases:
Icon Action Replacer v1.5- latest release
Current projects:
PSP C++ IDE - Currently v1.6
RPG Paradise - Latest version at my website
-
06-14-2007, 08:42 PM #5046Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
ah yes, you're right. just checked my book

havent used extern in a while ;)--------------------------------------------------------------------------------------
-
06-15-2007, 01:12 AM #5047QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
ok, the only problem i get now is,
Code:enemyAI.h(5) syntax error before 'zombie' enemyAI.h(5) [Warning] type defaults to 'int' in declaration of 'zombie' enemyAI.h(5) [Warning] data definition has no type or storage class
here is enemyAI.h,
EDIT: also, How would I Load an Eboot? IE, load the one I am using to "restart" it?Code:#ifndef __ENEMYAI__ #define __ENEMYAI__ extern void enemyAI(); extern ENEMY zombie[1]; #endif
Geändert von BlackShark (06-15-2007 um 01:35 AM Uhr)
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
06-15-2007, 01:37 AM #5048QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Re-read the error and look specifically at what it is referring to. Think of reasons of why it can't figure out what to do. One of the skills that any programmer must learn is to be able to compiler and execute code in their head. This includes the highlighting of errors.
Zitat von BlackShark
Spoiler for answer:[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
06-15-2007, 01:58 AM #5049QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
But enemyAI.c is what defines it, how would i include that in the enemyAI.h file?
#include "enemyAI.c" ?NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
06-15-2007, 02:04 AM #5050QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
No, don't EVER include source files. Just move the definition of ENEMY from the source file to the header file.
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
06-15-2007, 03:02 AM #5051QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
I knew that wouldn't work :P, Thanks!
alright, i know i must be driving you all crazy with this question attack of mine, so weather this is the last one I have or not, this will be the very last one i post....for tonight, (this morning, what ever :P)
ok, im still getting errors for that damn Image zombiepic :/,
the error list is this,
now if you remember, zombiepic is an Image I load in Game.c and would also like it to be available in enemyAI.c.Code:[Linker error] undefined reference to `zombiepic' K:\Black Pack\WorldWarZ\enemyAI.o R_MIPS_GPREL16 against `zombiepic'
I checked enemyAI.c to make sure it had Game.h included, here is the game.h
I tried "extern Image* zombiepic;" tooCode:#ifndef __GAME__ #define __GAME__ extern void Game(); extern Image *zombiepic; #endif
I also tried putting the * on zombiepic in the Game.c while loading like
Code:Image *zombiepic = loadImage("zombie");
but that didn't work either, I made sure that enemyAI.h was included in the Game.c too. Any ideas?NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
06-15-2007, 05:05 AM #5052QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Post up full code of Game.c as it is at the moment with that error.
-= Double Post =-
Code:// Header file #ifndef (BLAH_H) #define (BLAH_H) extern int * gAGlobal; #endif // (BLAH_H)
Code:// Source file where gAGlobal is instantiated // No need to include header file // IN GLOBAL SCOPE! int * gAGlobal = NULL; void blah( void ) { gAGlobal = someRandomValue; }Geändert von yaustar (06-15-2007 um 05:11 AM Uhr) Grund: Automerged Doublepost
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
06-15-2007, 06:22 AM #5053Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
Spoiler for code:
I am not able to go to a folder , why?
The first step works great , i see the files of the root and can move the mouse , but when i select something:
file : shows the text and crashes
folder : shows the text for files and carshes:s
-
06-15-2007, 10:10 AM #5054
i´ve got a question that may be hard to answer.
how do i use a .txt file for a map?
please give some examples and please don´t flame me
thanks
-
06-15-2007, 10:26 AM #5055
say your map file is like this:
Zitat von sony psp player
000010000
000110000
000111000
000111001
00...ect
All the '0's are grass or whatever and '1's are something else. You would make a loader that gets a char from the file and do that how many times the file is in length. You would check each char to see is it was a number with isdigit(ch); (ch is the char that was read from the file)
Just set the tiles accordingly or draw them, whateverCurrent releases:
Icon Action Replacer v1.5- latest release
Current projects:
PSP C++ IDE - Currently v1.6
RPG Paradise - Latest version at my website
-
06-15-2007, 11:00 AM #5056
can you make an example that is nearly working?
-
06-15-2007, 11:42 AM #5057
the way I do it isn't that reusable, it would be better to google it.
Current releases:
Icon Action Replacer v1.5- latest release
Current projects:
PSP C++ IDE - Currently v1.6
RPG Paradise - Latest version at my website
-
06-15-2007, 11:46 AM #5058
can you find something on google?
-= Double Post =-
i have another question
a string: abcdefghiklmnopqrstuvwxyz
how do i get the letters "cdefgh" out of this string?Geändert von sony psp player (06-15-2007 um 12:55 PM Uhr) Grund: Automerged Doublepost
-
06-15-2007, 01:23 PM #5059
you mean find them specifically or cut them out of it?
Current releases:
Icon Action Replacer v1.5- latest release
Current projects:
PSP C++ IDE - Currently v1.6
RPG Paradise - Latest version at my website
-
06-15-2007, 01:29 PM #5060
i have the beginning position and the end position and i wanna have them in another string, while the first string isn´t changed
-
06-15-2007, 01:39 PM #5061
Do get those specifically you would do this:
Code:int main() { char *str = "abcdefghiklmnopqrstuvwxyz"; char specific_data[10]; char *ptr; ptr = strstr(str,"cdefgh"); /*strstr returns the pointer to where "cdefgh" starts*/ strncpy(specific_data,ptr,6); /*copys "cdefgh" to string specific_data*/ //specific_data now holds "cdefgh" and str remains the same return 0; }Current releases:
Icon Action Replacer v1.5- latest release
Current projects:
PSP C++ IDE - Currently v1.6
RPG Paradise - Latest version at my website
-
06-15-2007, 01:41 PM #5062words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
sony_psp_player - There's multiple ways, but you still haven't answered the question. Would you like to be able to call a function saying:
if "cdefgh" is found in string "abcdefghijklmnopqrstuvwx yz" then ...
Or would you just like to take out the 3rd,4th,5th,6th,7th and 8th element out of an array of characters...
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
06-15-2007, 02:01 PM #5063QJ Gamer Bronze

- Registriert seit
- Jun 2006
- Beiträge
- 144
- Points
- 7.047
- Level
- 55
- Downloads
- 0
- Uploads
- 0
For maps you're better off with serialization. (Search on google)
Adrahil - Software architect and specialist in Reverse Engineering.
Spoiler for Guilt of a Dev:
Spoiler for me:
-
06-15-2007, 10:50 PM #5064
i wanna take out the 3rd,4th,5th,6th,7th and 8th, so if the string was
Zitat von SG57
"abcdefghijkl"
it would take out "cdefgh"
"ajsdafhdjajdkfja"
it would take out "sdafhd"
-
06-15-2007, 11:03 PM #5065words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
Ok. I suggest you read up on arrays and write it yourself, but if you get stuck or whatever, use this as a reference.
I haven't messed with strlen or sizeof in a long time, so I'm not sure whether strlen includes the '\0' and if sizeof reserves space for the '\0', so sorry ifthe numbering is off a little (a quick fix if so).Code:int grabber(char *dest_string, const char *source_string) { // for lack of a better function name static const MINIMUM_STRING_SIZE = 8; static const NUM_CHARS_TO_EXTRACT = 6; if(strlen(source_string) < MINIMUM_STRING_SIZE || sizeof(dest_string) < NUM_CHARS_TO_EXTRACT+1 /* compensate for '\0' */) return 0; // failure :( dest_string[0] = source_string[2]; dest_string[1] = source_string[3]; dest_string[2] = source_string[4]; dest_string[3] = source_string[5]; dest_string[4] = source_string[6]; dest_string[5] = source_string[7]; dest_string[6] = '\0'; // not sure whether this is automatically added or not, so it's a safety percaution return 1; // success :) }
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
06-15-2007, 11:45 PM #5066QJ Gamer Bronze

- Registriert seit
- Jun 2006
- Beiträge
- 144
- Points
- 7.047
- Level
- 55
- Downloads
- 0
- Uploads
- 0
Wow, you really like to make things complicated, SG57..... Just use strncpy ;)
Will yield "cdefgh" if alphabet is "abcdefghijklmnopqrstuvwx yz"Code:strncpy(dest, alphabet+2, 6);
Just don't forget to memset(dest, 0, XXX);, where XXX is the size of the dest buffer (declared as char dest[XXX];), and remember to make a buffer big enough so that there is a trailing 0 left.Adrahil - Software architect and specialist in Reverse Engineering.
Spoiler for Guilt of a Dev:
Spoiler for me:
-
06-15-2007, 11:55 PM #5067words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
I like manual conversions, it gives me a sense of safety for some reason.

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
06-16-2007, 12:06 AM #5068QJ Gamer Bronze

- Registriert seit
- Jun 2006
- Beiträge
- 144
- Points
- 7.047
- Level
- 55
- Downloads
- 0
- Uploads
- 0
Manual CONVERSIONS? :/ There are no "conversions" here... Moreover, there is no possible WAY in which you'd be able to outperform standard libc functions... I bet you'd not be able to understand completely the operation of functions such as these:
Zitat von SG57
(from OpenBSD source code repository for libc)Code:char * strncpy(char *dst, const char *src, size_t n) { if (n != 0) { char *d = dst; const char *s = src; do { if ((*d++ = *s++) == 0) { while (--n != 0) *d++ = 0; break; } } while (--n != 0); } return (dst); }
Well, to come back to the subject, your method is really unoptimized and is not made for a dynamic map loading, as the lengths are static. With strncpy, it is much easier to split a string into different parts...Adrahil - Software architect and specialist in Reverse Engineering.
Spoiler for Guilt of a Dev:
Spoiler for me:
-
06-16-2007, 12:18 AM #5069Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
why isnt it
Code:char * strncpy(char *dst, const char *src, size_t n) { if (n != 0) { char *d = dst; const char *s = src; if ((*d++ = *s++) == 0) { while (--n != 0) *d++ = 0; } } return (dst); }
-
06-16-2007, 12:24 AM #5070QJ Gamer Bronze

- Registriert seit
- Jun 2006
- Beiträge
- 144
- Points
- 7.047
- Level
- 55
- Downloads
- 0
- Uploads
- 0
Uhm... You're only copying one char here, no? (No while() loop to do (*d++ = *s++))... I think you meant "while((*d++ = *s++)...", but tbh, I think the code in the repository is the way they found it to be a good compromise between portability, speed and readability. :)
(There were a few comments in the original code, but i didn't bother to copy/paste them ;) )Adrahil - Software architect and specialist in Reverse Engineering.
Spoiler for Guilt of a Dev:
Spoiler for me:


LinkBack URL
About LinkBacks
Mit Zitat antworten

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum