[QUOTE=ZeekyHBomb;27426528][url=http://download.oracle.com/javase/7/docs/api/java/util/Hashtable.html]java.util.Hashtable<String, String>[/url]
Associate each name with the abbreviation, then you can check if the key is present in the hashtable and if so, simply get the abbreviation from it.[/QUOTE]
Thanks a lot, works perfect.
[QUOTE=pro ruby dev;27426739]With gcc, how can I compile a set of source files to a static library?
I've figured out how to compile into a shared library, and that way I don't have to declare a main() function, but I can't find how to compile to a static library.
Here's my current build script:
[code]
gcc -g -std=c99 -shared -o bin/kari.lib -Iinc `find src/. | grep \\.c$ | perl -e 'while(<>){chomp;print"$_ "}'`
gcc -g -o bin/ikari -Iinc repl/*.c bin/kari.lib
[/code][/QUOTE]
Change -shared to -static for the final -o output
[QUOTE=Chandler;27427638]Change -shared to -static for the final -o output[/QUOTE]
When I do that it says that it can't statically link to a shared library.
Anyways, I got it working thanks to that page sim642 linked:
[img]http://f.anyhub.net/1tSl[/img]
[QUOTE=Crhem van der B;27426061]People please don't laugh, but how can I make this shorter and not as ugly?[/QUOTE]
What are those "actualGame" names used for? If other parts of the program compare against those strings, an enum would be more appropriate:
[csharp]
public enum Game {
CALL_OF_DUTY("Call of Duty"),
CALL_OF_DUTY_2("Call of Duty 2"),
CALL_OF_DUTY_4("Call of Duty 4: Modern Warfare"),
CALL_OF_DUTY_WAW("Call of Duty: World at War"),
CALL_OF_DUTY_BO("Call of Duty: Black Ops"),
COUNTERSTRIKE("Counter-Strike 1.6"),
COUNTERSTRIKE_SOURCE("Counter-Strike: Source"),
DAY_OF_DEFEAT("Day of Defeat"),
DAY_OF_DEFEAT_SOURCE("Day of Defeat: Source"),
HALF_LIFE_2_DM("Half Life 2: Deathmatch"),
TEAM_FORTRESS_2("Team Fortress 2"),
;
private Game(final String title) {
this.title = title;
}
private final String title;
public String getTitle() {
return title;
}
private static final Map<String, Game> gamesByTitle = new HashMap<String, Game>();
static {
for (final Game game : Game.values()) {
gamesByTitle.put(game.getTitle(), game);
}
}
public static Game lookupByTitle(final String title) {
return gamesByTitle.get(title);
}
}
[/csharp]
Alternatively, it may be more appropriate to read the set of games from a data file rather than hard-coding it.
Zeeky, Hashtable is sort of deprecated, BTW; use HashMap instead.
Well,
[csharp]
// variable "game" is set
HashMap<String, String> games
= new HashMap<String, String>();
games.put("Call of Duty", "cod");
games.put("Call of Duty 2", "cod2");
games.put("Call of Duty 4: Modern Warfare", "cod4");
games.put("Call of Duty: World at War", "codwaw");
games.put("Call of Duty: Black Ops", "codbo");
games.put("Counter-Strike 1.6", "cs");
games.put("Counter-Strike: Source", "cssource");
games.put("Day of Defeat", "dod");
games.put("Day of Defeat Source", "dodsource");
games.put("Half Life 2: Deathmatch", "halflife2");
games.put("Team Fortress 2", "tf2");
String actualGame = games.get(game);
[/csharp]
Works just fine. And I send actualGame to a remote server, I don't compare it to anything.
I've been working on the console for a game I'm developing. I've been trying to figure out how to parse text in quotes as a big blob using streams. (in C++)
[cpp]
/*
* This is not what I exactly do. I basically take all my arguments and shove them in a vector which I pass as
* an argument to the console command's callback.
*
* I want the text in quotes to be parsed as one blob including the spaces. This would be used to allow people
* to have console command arguments with spaces in them.
*/
std::stringstream ss;
// simulating input
ss << "command arg1 arg3 arg3 \"arg4 with spaces\" arg5"
std::string tmp;
// printing each argument on a new line to see if it works
while (ss.good()){
ss >> tmp;
std::cout << tmp << std::endl;
}
[/cpp]
Now this would produce the following result;
[code]
command
arg1
arg3
arg3
"arg4
with
spaces"
arg5
[/code]
The result I want would be more in the lines of:
[code]
command
arg1
arg3
arg3
arg4 with spaces
arg5
[/code]
I have looked at the available manipulators for the stream and none seem to support this. There must be a way of doing this since most programs allow you to have quoted text handled as a single argument.
Summin like
[cpp]while(ss.good()){
if(ss.peek() == '\"'){
//discard the first "
ss.ignore(1);
std::getline(ss, tmp, '\"');
//discard the space following the "
/*TODO: check that
1) there was another quote (else ss.eof() will be true)
2) there actually was another space (however you wanna handle stuff like command arg1"arg2"arg3 is up to you)*/
ss.ignore(1);
}else{
std::getline(ss, tmp, ' ');
}
std::cout << tmp << std::endl;
}[/cpp]
Thanks, I had the same idea a few minutes after I wrote the post. I just needed a good way to read the first quote. That should do the job.
[editline]15th January 2011[/editline]
I did it a bit differently. I use the extractor operator so I don't have to worry about idiots putting 50 spaces and tab between arguments.
[cpp]
while (converter.good()) {
// get the first string
converter >> cArg;
// check if it starts with a quote
if (cArg.size() > 0 && cArg.at(0) == '\"') {
// remove the first quote
cArg.erase(0, 1);
// rest of the string
std::string rest;
// keep searching until we find another quote
std::getline(converter, rest, '\"');
// add to vector
args.push_back(cArg + rest);
} else
// add to args vector
args.push_back(cArg);
}
[/cpp]
[QUOTE=ZeekyHBomb;27322885]-static-libgcc[/QUOTE]
Im linking to gcc like this, however i still get the stupid "libgcc_s_dw2-1.dll missing" message when i try to run a program
Any one that uses SFML with openGL, can you give me a hand?
I have [url]http://pastebin.com/kKbvS6FD[/url]
But its not drawing anything, not even the square :/ i have got SFML runing openGL before but it doesnt want to work now
Also what should be in you declaration and your function call if you want to pass a reference of an array?
[QUOTE=Crhem van der B;27428610]And I send actualGame to a remote server, I don't compare it to anything.[/QUOTE]
In that case I'd recommend putting the game info in a data file, rather than hard-coding it in the program. The program itself doesn't care about the specific values, and there should be no need to recompile the program if the server's supported game list changes.
Turns out the not drawing was due to me not passing the array right.
Can anyone explain how to pass a reference of an array?
[QUOTE=Richy19;27442846]Turns out the not drawing was due to me not passing the array right.
Can anyone explain how to pass a reference of an array?[/QUOTE]
You dont, you can just pass the array. An array itself is just a pointer to a block of memory with a certain size
[QUOTE=Icedshot;27443244]You dont, you can just pass the array. An array itself is just a pointer to a block of memory with a certain size[/QUOTE]
Whats wrong with this then?
[cpp]//main cpp
const int height = 100;
const int width = 120;
sf::Vector3f myVector3D [width][height];
fillVect(myVector3D, seed,octaves,persistence,zoom);
[/cpp]
[cpp]//file header
void fillVect(sf::Vector3f myVect[][], int seed,int octaves, float persistence, int zoom);
[/cpp]
[cpp]//file cpp
void fillVect(sf::Vector3f myVect[][], int seed,int octaves, float persistence, int zoom)
{
...
}[/cpp]
[quote]
declaration of 'myVect' as multidimensional array must have bounds for all dimensions except the first
[/quote]
You can't have a multi dimensional array of variable size in C++. the second [] must have a given size.
Use a vector of vectors instead.
[QUOTE=shill le 2nd;27444766]Use a vector of vectors instead.[/QUOTE]
That works but it's not very efficient since each sub-array is allocated separately. It's simpler to allocate a 1D vector and convert the 2D array coordinates to 1D, by multiplying the row number by the number of columns.
Working on a touchless prototype for nokia but i'm stuck: :saddowns:
[URL]http://www.facepunch.com/threads/1049683-Need-help-packaging-a-mobile-app[/URL]
[QUOTE=Wyzard;27446018]That works but it's not very efficient since each sub-array is allocated separately. It's simpler to allocate a 1D vector and convert the 2D array coordinates to 1D, by multiplying the row number by the number of columns.[/QUOTE]
I like your C thinking.
There's also the [url=http://live.boost.org/doc/libs/release/libs/multi_array/index.html]Boost MultiArray[/url].
and Blitz array
[code]- (void) addBoard:(board)boardToAdd toLocation:(int)x :(int)y {
for (int height = 0; height<boardToAdd.height; height++) {
for (int length = 0; length<boardToAdd.length; length++) {
floorUnderConstruction.array[y+height][x+length] = boardToAdd.array[height][length];
}
}
}[/code]
This code adds the contents of one 2D array to another. It works fine, but I want to add something to it.
At the moment, the value at x,y will be replaced with the value at 0,0 on the array being added. How can I set it so that the value at x,y will be replaced [b]by the value at a specific point on the array I'm adding[/b]?
[QUOTE=ProWaffle;27452029]This code adds the contents of one 2D array to another. It works fine, but I want to add something to it.
At the moment, the value at x,y will be replaced with the value at 0,0 on the array being added. How can I set it so that the value at x,y will be replaced [b]by the value at a specific point on the array I'm adding[/b]?[/QUOTE]
Would changing the starting values of height and length to whatever you want to be the specific point work?
[img]http://i.cubeupload.com/qk0vcR.png[/img]
That should help.
Hang on, as most of you understand C but not Objective-C, I'll make it a function...
[editline]16th January 2011[/editline]
[code]void addBoard(board boardToAdd, int x int y) {
for (int height = 0; height<boardToAdd.height; height++) {
for (int length = 0; length<boardToAdd.length; length++) {
floorUnderConstruction.array[y+height][x+length] = boardToAdd.array[height][length];
}
}
}[/code]
floorUnderConstruction is an already existing ivar. It is in context. It's a 64-128x64-128 2D array.
[editline]16th January 2011[/editline]
The "board" type consists of a 2D array, and 2 ints, length and height. floorUnderConstruction and boardToAdd are boards.
In wxPython...
I'm using Python 2.71 (2.8?) and I'm trying to make it so when a checkbox is checked, the images will change too. What can you use to get the value of wx.CheckBox()?
[code]self.pics=[1.jpg, 2.jpg, 3.jpg]
check=wx.CheckBox(self, -1, "Show info", (30, 30), (160, -1))
if check.getthevalueofiftheboxischecked() = true:
//Obviously not how you get it, but thats because
//I don't know the actual way to get value, which I'm asking for, and the real thing
//Probably doesn't return like that, so whatever
self.pics=[1a.jpg, 2a.jpg, 3a.jpg][/code]
Basically, how do I get value of checkbox?
I want to make a program that can interact with other programs (i.e. a simple program that reads the weather report from the weather widget and then prints the temperature); how would I go about doing this? Would it be easier to do with C++ or with Python? I'm currently using Ubuntu 10.10.
Anyone have a good tutorial for making a Socket server in C++? I have made servers in Java so I know generally how they work, I just need something that explains the C++ methods and stuff. Everything I have found via Google either doesn't even work, or just gives me uncommented source code I can't even begin to dissect.
[QUOTE=redonkulous;27460276]Anyone have a good tutorial for making a Socket server in C++? I have made servers in Java so I know generally how they work, I just need something that explains the C++ methods and stuff. Everything I have found via Google either doesn't even work, or just gives me uncommented source code I can't even begin to dissect.[/QUOTE]
Winsock is how sockets are usually done in C++.
Here's what appears to be a decent tutorial: [url]http://johnnie.jerrata.com/winsocktutorial/[/url]
But if that one doesn't suit you, just google "winsock tutorial" and there'll be a lot of results.
Ok I have a question that I guess isn't TECHNICALLY about programming but I didn't know where else to go with it.
Okay so me and a partner are working on a tycoon type game where you own a Game development studio and when you start development you can choose from a basic, broad 5 genres which are Action, Adventure, Puzzle, Sports, and Strategy.
Now we were thinking that after you choose one of these broad ones you could just type in what subgenre you wanted like FPS, RPG, RTS, and etc. because it would be a pain in the ass to make it selectable from a menu and what you typed in could be used in reviews for your game and fan letters and whatever else.
My question is: Do you think we really need that feature to type in the subgenre? Because I say its pretty necessary and he says those first basic 5 are good enough so what do YOU think?
I would say don't bother with a sub-genre option, but have the option for a player to enter some "tags" for his/her game, such as:
Genre: Action
Tags: "online", "fps"
Then have a system that picks some words from those tags and uses them in reviews and so on
Sorry, you need to Log In to post a reply to this thread.