Skip to content

Commit

Permalink
Galileo, Module prebuild
Browse files Browse the repository at this point in the history
- client
  * Module::prebuild
  * Module::listModules
  * Galileo navigation module
    + GalileoFrame
    + Lua bindings to set markers
  * Quest module
  * serialisation of modules
  • Loading branch information
ducakar committed Oct 6, 2011
1 parent dca3683 commit 4542d74
Show file tree
Hide file tree
Showing 18 changed files with 478 additions and 46 deletions.
2 changes: 2 additions & 0 deletions src/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_library( client STATIC
MD3.cpp
MenuStage.cpp
Mesh.cpp
Module.cpp
Network.cpp
OBJ.cpp
OpenAL.cpp
Expand Down Expand Up @@ -61,6 +62,7 @@ add_library( client STATIC
modules/MusicPlayer.cpp
modules/MusicPlayerModule.cpp
modules/ProfileModule.cpp
modules/QuestModule.cpp
)
add_dependencies( client nirvana matrix pch )

Expand Down
1 change: 1 addition & 0 deletions src/client/Context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ namespace client
static uint loadRawTexture( const char* path, bool wrap = true,
int magFilter = DEFAULT_MAG_FILTER,
int minFilter = DEFAULT_MIN_FILTER );

static void writeTexture( uint id, OutputStream* stream );

#endif
Expand Down
40 changes: 14 additions & 26 deletions src/client/GameStage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,14 @@

#include "nirvana/Nirvana.hpp"

#include "client/Network.hpp"
#include "client/Loader.hpp"
#include "client/Render.hpp"
#include "client/Sound.hpp"
#include "client/Network.hpp"
#include "client/Camera.hpp"
#include "client/Lua.hpp"
#include "client/MenuStage.hpp"

#include "client/modules/ProfileModule.hpp"
#include "client/modules/FloraModule.hpp"
#include "client/modules/MusicPlayerModule.hpp"
#include "client/modules/GalileoModule.hpp"

#define OZ_REGISTER_MODULE( module ) \
modules.add( &module##Module )
#include "client/Module.hpp"

namespace oz
{
Expand Down Expand Up @@ -358,12 +351,19 @@ namespace client

log.printEnd( " OK" );

context.load();
render.load();

ui::mouse.doShow = true;
ui::mouse.buttons = 0;
ui::mouse.currButtons = 0;

camera.reset();

for( int i = modules.length() - 1; i >= 0; --i ) {
modules[i]->load();
}

if( !onCreate.isEmpty() ) {
log.println( "Initialising new world" );

Expand All @@ -377,13 +377,6 @@ namespace client
throw Exception( "reading saved state '" + stateFile + "' failed" );
}

context.load();
render.load();

for( int i = modules.length() - 1; i >= 0; --i ) {
modules[i]->load();
}

camera.update();
camera.prepare();

Expand Down Expand Up @@ -415,17 +408,17 @@ namespace client
render.draw( Render::DRAW_UI_BIT );
render.sync();

if( isLoaded ) {
write( AUTOSAVE_FILE );
}

for( int i = modules.length() - 1; i >= 0; --i ) {
modules[i]->unload();
}

render.unload();
context.unload();

if( isLoaded && config.getSet( "gameStage.autosave", true ) ) {
write( AUTOSAVE_FILE );
}

log.print( "Stopping auxilary thread ..." );

isAlive = false;
Expand All @@ -448,8 +441,6 @@ namespace client
nirvana.unload();
matrix.unload();

camera.reset();

ui::ui.showLoadingScreen( false );

isLoaded = false;
Expand All @@ -471,10 +462,7 @@ namespace client
onCreate = "";
stateFile = "";

OZ_REGISTER_MODULE( profile );
OZ_REGISTER_MODULE( flora );
OZ_REGISTER_MODULE( musicPlayer );
OZ_REGISTER_MODULE( galileo );
Module::listModules( &modules );

matrix.init();
nirvana.init();
Expand Down
40 changes: 40 additions & 0 deletions src/client/Module.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Module.cpp
*
* [description]
*
* Copyright (C) 2002-2011 Davorin Učakar
* This software is covered by GNU GPLv3. See COPYING file for details.
*/

#include "stable.hpp"

#include "client/Module.hpp"

#include "client/modules/ProfileModule.hpp"
#include "client/modules/FloraModule.hpp"
#include "client/modules/MusicPlayerModule.hpp"
#include "client/modules/GalileoModule.hpp"

#define OZ_REGISTER_MODULE( module ) \
list->add( &module##Module )

namespace oz
{
namespace client
{

void Module::listModules( Vector<Module*>* list )
{
#ifndef OZ_TOOLS
OZ_REGISTER_MODULE( profile );
OZ_REGISTER_MODULE( flora );
OZ_REGISTER_MODULE( musicPlayer );
OZ_REGISTER_MODULE( galileo );
#else
OZ_REGISTER_MODULE( galileo );
#endif
}

}
}
7 changes: 7 additions & 0 deletions src/client/Module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace client
{
public:

static void listModules( Vector<Module*>* list );

virtual ~Module()
{}

Expand Down Expand Up @@ -49,6 +51,11 @@ namespace client
virtual void free()
{}

#ifdef OZ_TOOLS
virtual void prebuild()
{}
#endif

};

}
Expand Down
8 changes: 4 additions & 4 deletions src/client/Shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ namespace client
// sprite
vertices[24] = Vertex( Point3( -1.0f, -1.0f, 0.0f ),
TexCoord( 0.0f, 0.0f ),
Vec3( 0.0f, -1.0f, 0.0f ) );
Vec3( 0.0f, 0.0f, 1.0f ) );
vertices[25] = Vertex( Point3( +1.0f, -1.0f, 0.0f ),
TexCoord( 1.0f, 0.0f ),
Vec3( 0.0f, -1.0f, 0.0f ) );
Vec3( 0.0f, 0.0f, 1.0f ) );
vertices[26] = Vertex( Point3( -1.0f, +1.0f, 0.0f ),
TexCoord( 0.0f, 1.0f ),
Vec3( 0.0f, -1.0f, 0.0f ) );
Vec3( 0.0f, 0.0f, 1.0f ) );
vertices[27] = Vertex( Point3( +1.0f, +1.0f, 0.0f ),
TexCoord( 1.0f, 1.0f ),
Vec3( 0.0f, -1.0f, 0.0f ) );
Vec3( 0.0f, 0.0f, 1.0f ) );

// box
vertices[28] = Vertex( Point3( -1.0f, -1.0f, -1.0f ) );
Expand Down
4 changes: 2 additions & 2 deletions src/client/Terra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ namespace client
vertex.pos[1] = pos.y;
vertex.pos[2] = pos.z;

vertex.texCoord[0] = float( x ) / float( oz::Terra::VERTS );
vertex.texCoord[1] = float( y ) / float( oz::Terra::VERTS );
vertex.texCoord[0] = 1.0f - float( x ) / float( oz::Terra::VERTS );
vertex.texCoord[1] = 1.0f - float( y ) / float( oz::Terra::VERTS );

vertex.normal[0] = normal.x;
vertex.normal[1] = normal.y;
Expand Down
129 changes: 124 additions & 5 deletions src/client/modules/GalileoFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,143 @@

#include "client/modules/GalileoFrame.hpp"

#include "client/Camera.hpp"
#include "client/Context.hpp"

#include "client/modules/GalileoModule.hpp"

#include "client/OpenGL.hpp"

namespace oz
{
namespace client
{
namespace ui
{

GalileoFrame::GalileoFrame() :
Frame( 8, -8, 400, 400, "" )
uint GalileoFrame::loadTexture( const char* path ) const
{
flags = PINNED_BIT;
Buffer buffer;

if( !buffer.read( path ) ) {
throw Exception( "Failed reading galileo texture '" + String( path ) + "'" );
}

show( false );
InputStream istream = buffer.inputStream();
return context.readTexture( &istream );
}

bool GalileoFrame::onMouseEvent()
{
return isVisible ? Frame::onMouseEvent() : false;
}

void GalileoFrame::onDraw()
{
Frame::onDraw();
if( camera.state == Camera::BOT && camera.botObj != null ) {
const Vector<int>& items = camera.botObj->items;

for( int i = 0; i < items.length(); ++i ) {
const Object* item = orbis.objects[ items[i] ];

if( item != null && item->clazz->name.equals( "galileo" ) ) {
goto galileoEnabled;
}
}

isVisible = false;
return;
}

galileoEnabled:;

isVisible = true;

if( mapTexId == 0 ) {
mapTexId = loadTexture( "ui/galileo/" + library.terras[orbis.terra.id].name + ".ozcTex" );
}

float pX;
float pY;
float h;

if( camera.state == Camera::BOT && camera.botObj != null ) {
pX = camera.botObj->p.x;
pY = camera.botObj->p.y;
h = camera.botObj->h;
}
else {
pX = camera.p.x;
pY = camera.p.y;
h = camera.h;
}

glUniform4f( param.oz_Colour, 1.0f, 1.0f, 1.0f, 0.6f );
glBindTexture( GL_TEXTURE_2D, mapTexId );
fill( 0, 0, width, height );

glUniform4f( param.oz_Colour, 1.0f, 1.0f, 1.0f, 1.0f );

float oX = float( x );
float oY = float( y );
float fWidth = float( width );
float fHeight = float( height );

glBindTexture( GL_TEXTURE_2D, markerTexId );

for( int i = 0; i < galileoModule.markers.length(); ++i ) {
float mapX = oX + ( Orbis::DIM + galileoModule.markers[i].x ) / ( 2.0f*Orbis::DIM ) * fWidth;
float mapY = oY + ( Orbis::DIM + galileoModule.markers[i].y ) / ( 2.0f*Orbis::DIM ) * fHeight;

tf.model = Mat44::translation( Vec3( mapX, mapY, 0.0f ) );
tf.model.scale( Vec3( 16.0f, 16.0f, 0.0f ) );
tf.model.translate( Vec3( -0.5f, -0.5f, 0.0f ) );
tf.apply();

glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
}

glBindTexture( GL_TEXTURE_2D, arrowTexId );

float mapX = oX + ( Orbis::DIM + pX ) / ( 2.0f*Orbis::DIM ) * fWidth;
float mapY = oY + ( Orbis::DIM + pY ) / ( 2.0f*Orbis::DIM ) * fHeight;

tf.model = Mat44::translation( Vec3( mapX, mapY, 0.0f ) );
tf.model.rotateZ( h );
tf.model.scale( Vec3( 10.0f, 10.0f, 0.0f ) );
tf.model.translate( Vec3( -0.5f, -0.5f, 0.0f ) );
tf.apply();

glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );

glBindTexture( GL_TEXTURE_2D, 0 );
}

GalileoFrame::GalileoFrame() :
Frame( 8, -60 - Font::INFOS[Font::SMALL].height - Font::INFOS[Font::LARGE].height,
240, 232 - Font::INFOS[Font::LARGE].height, "" ),
mapTexId( 0 ), arrowTexId( 0 ), markerTexId( 0 ), isVisible( true )

{
arrowTexId = loadTexture( "ui/galileo/arrow.ozcTex" );
markerTexId = loadTexture( "ui/galileo/marker.ozcTex" );

if( !ui::mouse.doShow ) {
show( false );
}
}

GalileoFrame::~GalileoFrame()
{
if( mapTexId != 0 ) {
glDeleteTextures( 1, &mapTexId );
}
if( arrowTexId != 0 ) {
glDeleteTextures( 1, &arrowTexId );
}
if( markerTexId != 0 ) {
glDeleteTextures( 1, &markerTexId );
}
}

}
Expand Down
11 changes: 11 additions & 0 deletions src/client/modules/GalileoFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,24 @@ namespace ui

class GalileoFrame : public Frame
{
private:

uint mapTexId;
uint arrowTexId;
uint markerTexId;
bool isVisible;

uint loadTexture( const char* path ) const;

protected:

virtual bool onMouseEvent();
virtual void onDraw();

public:

GalileoFrame();
virtual ~GalileoFrame();

};

Expand Down
Loading

0 comments on commit 4542d74

Please sign in to comment.