Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Game Blackboard  RSS feed

 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to implement a blackboard for my game I"m designing. Basically, it registers and stores any object and lets me retrieve that object again at a later time. How would I go about doing this?


This is what I have so far:



 
Bartender
Posts: 4223
48
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not idea what you're talking about.

Do you know about Maps? Do you know about Serialization? Do you know about databases?

"some time later", how much later?
 
Saloon Keeper
Posts: 8892
166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't extend the Thread class. If you need tasks performed in the background, use an ExecutorService. It doesn't seem like your class represents a task anyway.

What kind of game are you making, and why do you need a central place to store variables?
 
Ted Gress
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Yesterday ‎10‎:‎58‎:‎15‎ ‎PM     Subject: Game Blackboard

I have not idea what you're talking about.

Do you know about Maps? Do you know about Serialization? Do you know about databases?

"some time later", how much later? 



Yes I know about maps. And I know about Serialization. And I know about databasesI don't think any of that that applies to this situation though.


Yesterday ‎10‎:‎58‎:‎15‎ ‎PM     Subject: Game Blackboard

I have not idea what you're talking about.

Do you know about Maps? Do you know about Serialization? Do you know about databases?

What kind of game are you making, and why do you need a central place to store variables? 



I am making a 3D MMORPG. I read about them as an algorithm for use when there is a lot of cross-information s haring.
I wish I had the reference.

But that is a moot point. Can somebody answer my question?

 
Stephan van Hulst
Saloon Keeper
Posts: 8892
166
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not a moot point, because knowing the reasons why will help find the correct solution.

Why do you think that using maps is not the correct solution? That's the first thing I would consider when I want to store variables in memory.
 
Ted Gress
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using maps makes perfect sense in this situation. H ow else would you store a key value pair?
 
Stephan van Hulst
Saloon Keeper
Posts: 8892
166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does that mean you've found something that works for you?
 
Ted Gress
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really. I want to store instances of classes in the blackboard. I'm thinking maybe Java Generics would work?
 
Stephan van Hulst
Saloon Keeper
Posts: 8892
166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maps are generic.

Can you give us concrete examples of the things you want to store?
 
Ted Gress
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Wrong term. I don't know what its called in Java, I thought it was Generics. I want to use something like templates in C++.


Here is some pseudocode:



Blackboard.register(variable's name, variable's value)

Blackboard.register(pointLight, pointLight.value)

--

vector pointLight = Blackboard.retrieve(variable's name)

--
TextureMap t;

Blackboard.register(t, t.value);

(rendering loop)

TextureMap t = Blackboard,.retrieve(t);

--------------


So, these are just examples. I wouldn't necessarily use the BlackBoard to store those values, but it shoujld clear things up.



 
Carey Brown
Bartender
Posts: 4223
48
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Map's are collections. They use generics to specify the types they're dealing with.
To declare a Map you need Map<K,V> where 'K' is the object type for the key, and 'V' is the object type for the value. Keys stored in the Map must be unique. Map entries are "registered" using the put() method, and "retrieved" with the get() method.

Blackboard blackboard = new Blackboard(...);

// asuming your Blackboard class has a Map variable by the name of "map"
blackboard.map.put( "unique name", variable );
blackboard.map.put( "pointLight", pointLight );

--

PointLight pointLight = blackboard.map.get( "pointLight" );

--
TextureMap t;
blackboard.map.put( "textureMap", t );

(rendering loop)

TextureMap t = blackboard.map.get( "textureMap" );

--------------
Here I'm assuming that your Map declaration inside your Blackboard class would look like

 
Ted Gress
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need something more along the lines of:

Map<"String Identifier", Object>

Where object is any type. AIs t his possible?
 
Marshal
Posts: 59092
180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ted Gress wrote:. . . Map<"String Identifier", Object> . . .

No, you have to write types not objects in the <>. Map<String, Object> will work.
 
Ted Gress
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, does that mean I can do the following? (for example)


Hashmap<String, T> myBlackboard = new Hashmap<String, T>

variables:

ambientlight = 1.0f;
long frameTime = endTime - FrameTime
WSObject WSFirstPersonPlayerCharacter = new WSFirstPersonPlayerCharacter();

then

myBlackboard.put("ambientlight", ambientlighit);

myBlackboarrd.put("frameTime", frameTime);

myBlackboard.put("FIrstPersonPlayerCharacter", WSFirstPersonPlayerCharacter());



 
Ted Gress
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correction: That last line is supposed to be:

myBlackboard.put("WSFirstPersonPlayerCharacter", WSFirstPersonPlayerCharacter)
 
Good heavens! What have you done! Here, try to fix it with this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!