Hi Rob,
First, ditto on Howard's response ("Stop right there..." etc.). It is crucial to understand what should happen on and off the island. The following might also be helpful. It is a snippet of code to create a new master, and to create a cube in the space. Since it is always easier to start from something that works, I hope that this helps you get started. "Execute the following line separately from the rest, and wait until you see the world running." master := CroquetMaster new openInWorld. "Execute the following lines either separately or together, it doesn't matter." harness := master instVarNamed: #harness. "sorry, there is no accessor" spaceRef := harness avatar replica island future at: #masterSpace. cubeRef := spaceRef island future new: TCube. spaceRef future addChild: cubeRef. The most straightforward way to adapt this to your own needs is to substitute your own class instead of TCube, and then send future messages to configure it with the parameters from the database. For example, after executing the code above, you can execute something like this in the same workspace: [ [ "This contains your custom code to get descriptions of new objects from the database." newObjectDescriptions := databaseInterface getNewObjectDescriptions. newObjectDescriptions do: [:desc | objRef := spaceRef island future new: desc classOfObjectToCreate. objRef future translation: desc translation. ]. (Delay forSeconds: 300) wait. "Wait 5 minutes to check the database again. ] repeat ] fork Howard notes that some people like to minimize the number of future messages that they use, and that it is typically considered to be good style to send one future message to an object on the island that causes the creation and initialization of a new object to occur. In your case, I would like to reiterate that you cannot do things this way: the database lookup MUST happen outside the island, since if it happens on the island, each replica will do the lookup, and there is no guarantee that they will get the same result (due to race conditions, etc.) Good luck, Josh On Dec 5, 2006, at 11:48 AM, Rob Van Pamel wrote: > Hi > > I'm very sorry to bother you again. But I really don't get a clue. > When we look at the example of the simpleDemoWorld. > There we have the following. > > SimpleWorld>>#initialize > Space := TSpace new. > Space registerGlobal:#masterSpace > > This is the place where we make the space global for external use. > > If we then look at CroquetHarness>>#setupMaster > > Island := self createIsland: SimpleWorld named:'Master". > Space := island future at:#masterSpace > > Now the space is connected from the CroquetHarness connected to the > Space of > the SimpleDemoWorld. And we can access that space in the > CroquetHarness for > adding object? > When I look deeper into the code, I see lots of other code. And I > see that > they also call the following. > > CroquetMaster>>#setup > harness := CroquetHarness new. (This will call the init method I > suppose) > harness setupMaster. > harness addOverlay: self. > > Do I have to do that also ? or am I digging to deep? I though > creating a > NavigatorWorld and NavigatorMaster was enough... > > Kind regards > Rob Van Pamel > > -----Oorspronkelijk bericht----- > Van: Joshua Gargus [mailto:[hidden email]] > Verzonden: maandag 4 december 2006 21:09 > Aan: Rob Van Pamel > Onderwerp: Re: [croquet] Create a new object. > > You don't see your avatar in the space, either? Are you creating > multiple spaces in NavigatorWorld? Maybe your avatar isn't in the > same space as the cube is being added to. > > One nice thing about Squeak is that you can send messages manually to > objects that you have a reference to. For example, in the bottom > pane of the inspector on the TFarRef: > > self future addChild: (myIsland future new: TCube) > > Does the cube show up in the space? If not, then something is very > very wrong. > > Josh > > > On Dec 4, 2006, at 12:04 PM, Rob Van Pamel wrote: > >> Hi >> >> No i don't see it there... So it isn't a good reference I guess. >> Perhaps >> there is something else wrong with my TFarRef. >> Do you have any idea's? >> >> Rob >> >> >> >> -----Oorspronkelijk bericht----- >> Van: Joshua Gargus [mailto:[hidden email]] >> Verzonden: maandag 4 december 2006 20:12 >> Aan: Rob Van Pamel >> Onderwerp: Re: [croquet] Create a new object. >> >> Hi Rob, >> >> That's interesting. I wonder if you're in the space that you think >> you are? >> >> If you explore 'aTSpace' (do you know about the ObjectExplorer? >> Google it if not; it's useful for investigating hierarchical >> structures). Do you see the green cube there? Do you see your >> avatar there? >> >> Josh >> >> >> On Dec 4, 2006, at 10:42 AM, Rob Van Pamel wrote: >> >>> Hi Joshua >>> >>> I've done the things like you said it but it didn't worked out. >>> I think my TfarRef works because when I inspect it , it give's me >>> the >>> following >>> >>> myIsland: a TIsland(DMU Navigator World (laptop.telenet.be)) >>> myValue: a TSpace >>> myName: OID:[eee2b6765add779a2cb0fc14bedfac7a] >>> >>> But when I add a cube to it, it doesn't appear in my space. I have >>> done >>> it with the following code >>> >>> fooCubeRef := island future new: Greencube. >>> spaceRef future addChild: fooCubeRef. >>> >>> Is there something else that I have to do first? Perhaps something >>> in my >>> Navigatorworld? >>> >>> Thanks a lot >>> >>> Here is the code that I have runned. I haven't putted in into a >>> different >>> process because I wanted to do it first very basic. >>> >>> NavigatorMaster>>setup >>> | pc sync entry island postcard myName spaceRef fooCubeRef | >>> running := false. >>> self startStepping. >>> harness := CroquetHarnessWithMenu new. >>> harness addOverlay: self. >>> myName := 'DMU Navigator World (',NetNameResolver >>> localHostName,')'. >>> island := harness createIsland: NavigatorWorld named: myName. >>> entry := self registerPortal: #mainEntry in: island. >>> >>> island := harness createIsland: NavigatorWorld named: myName. >>> spaceRef := island "a TFarRef to the island" future at: #mainEntry. >>> spaceRef wait. "wait for the future message to resolve" >>> >>> fooCubeRef := island future new: Greencube. >>> spaceRef future addChild: fooCubeRef. >>> spaceRef inspect. >>> >>> >>> harness makeSnapshot: (island future at: #mainEntry) angle: 0 >>> translation:(Vector3 x: 0 y: 0 z: 0). >>> postcard := TPostcard new routerAddress: nil "don't know what it >>> is" >>> id: nil "don't know what it is" >>> name: myName >>> viewpointName: #mainEntry. >>> harness viewPortal future postcardLink: postcard. >>> harness findViewpointByPostcard: postcard. >>> >>> "Drop into the intro world" >>> pc := entry future postcard. >>> pc whenResolved:[ >>> sync := harness viewPortal future postcardLink: pc value. >>> sync whenResolved:[harness startRender]. "ready to render" >>> ]. >>> pc wait. >>> >>> >>> >>> -----Oorspronkelijk bericht----- >>> Van: Joshua Gargus [mailto:[hidden email]] >>> Verzonden: maandag 27 november 2006 19:42 >>> Aan: Rob Van Pamel >>> CC: [hidden email] >>> Onderwerp: Re: [croquet] Create a new object. >>> >>> Rob, I forwarded one of your previous emails to the list to provide >>> context for others who might wish to learn from this discussion. I >>> hope that you don't mind. >>> >>> On Nov 27, 2006, at 6:03 AM, Rob Van Pamel wrote: >>> >>>> Hi josh, >>>> >>>> I'm sorry but I don't understand it completely. >>>> I understand that I have to work with a TfarReference because my >>>> Island is >>>> isolated from my stepper. >>> >>> That's correct. >>> >>>> To access my island I created an instance variable not an a global >>>> one. But >>>> it is available al over the class that's why I called it an global >>>> variable. >>> >>> OK. The reason I called it a global variable is that you registered >>> it as an Island global variable with #registerGlobal: >>> >>>> >>>> So now I have to create an global variable with registerglobal in >>>> the >>>> NavigatorMaster and then I can access this variable trough future >>>> sends? >>>> >>> >>> No, you should be able to create the global variable just fine in >>> NavigationWorld, just like you are. What you should not do is stash >>> a direct reference to the space and then reference it from your >>> stepper. After the island is finished creating, you can access the >>> 'island global' as I described, which gives you a TFarRef to the >>> space. >>> >>> spaceRef := island "a TFarRef to the island" future at: #mainEntry. >>> >>> islandRef := spaceRef island >>> >>>> Do you perhaps have a example in which you work with these future >>>> sends? >>>> Because I'm trying to find out but I don't think I'm going to make >>>> it. >>> >>> There are (at least) two approaches you might take. The following >>> code assumes that you have already executed the line (in >>> NavigationMaster) >>> island := harness createIsland: NavigatorWorld named: myName. >>> and that you have obtained a reference to the space: >>> spaceRef := island "a TFarRef to the island" future at: #mainEntry. >>> spaceRef wait. "wait for the future message to resolve" >>> >>> (I won't get into details, but it would have been fine to send other >>> future messages to spaceRef without first calling #wait) >>> >>> Now assume that you have looked in your database and decided that >>> you >>> need to create a new Foocube in the space. The first approach is to >>> gradually construct the object via a series of future messages: >>> >>> fooCubeRef := island future new: Foocube. >>> fooCubeRef future setParameterOne: dataFromDatabase. >>> fooCubeRef future setParameterTwo: moreDataFromDatabase. >>> "etc." >>> spaceRef future addChild: fooCubeRef >>> >>> A second approach is to completely create the Foocube outside the >>> island, then serialize it, then instantiate a copy in the space by >>> deserializing it. (a varation on this approach might be very good >>> for you: you could skip the Foocube creation step and directly >>> store >>> the serialized data in the database. >>> >>> fooCube := Foocube new. >>> fooCube setParameterOne: dataFromDatabase. >>> fooCube setParameterTwo: moreDataFromDatabase. >>> serialized := TIslandCopier new export: fooCube. >>> fooCubeRef := TIslandCopier new import: serialized to island. >>> spaceRef future addChild: fooCubeRef >>> >>> Let me know how it goes. If you have problems, it might be >>> because I >>> made a mistake somewhere (I didn't run the code). >>> >>> Josh >>> >>> >>> >>>> >>>> Thanks in advantage >>>> Rob Van Pamel >>>> >>>> >>> >>> <myCroquet2.st> >> >> > > |
Free forum by Nabble | Edit this page |