Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Functions | Variables
slot.cpp File Reference
#include <boost/algorithm/clamp.hpp>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <memory>
#include "inexor/client/network.hpp"
#include "inexor/engine/material.hpp"
#include "inexor/engine/octa.hpp"
#include "inexor/engine/octaedit.hpp"
#include "inexor/engine/octarender.hpp"
#include "inexor/engine/octree.hpp"
#include "inexor/engine/renderbackground.hpp"
#include "inexor/engine/renderva.hpp"
#include "inexor/engine/world.hpp"
#include "inexor/fpsgame/client.hpp"
#include "inexor/io/Logging.hpp"
#include "inexor/io/filesystem/mediadirs.hpp"
#include "inexor/io/legacy/stream.hpp"
#include "inexor/network/SharedVar.hpp"
#include "inexor/network/legacy/cube_network.hpp"
#include "inexor/shared/command.hpp"
#include "inexor/shared/cube_formatting.hpp"
#include "inexor/shared/tools.hpp"
#include "inexor/texture/cubemap.hpp"
#include "inexor/texture/image.hpp"
#include "inexor/texture/macros.hpp"
#include "inexor/texture/slot.hpp"
#include "inexor/texture/texture.hpp"

Classes

struct  slottex
 Legacy texture slot loading. More...
 

Functions

void texturereset (int first, int num)
 Resets all textures from the slots-stack. More...
 
 ICOMMAND (texturereset,"ii",(int *first, int *last), texturereset(*first,*last))
 
void materialreset ()
 
 COMMAND (materialreset,"")
 
void clearslots ()
 
static void assignvslot (VSlot &vs)
 Set the vs.index according to compactvslots global counter. More...
 
static void assignvslotlayer (VSlot &vs)
 
void compactvslot (int &index)
 compacting mode: set index to compactvslots++ = vs.index, marking mode, just set vs.index More...
 
void compactvslot (VSlot &vs)
 
void compactvslots (cube *c, int n)
 Loops through all n subcubes of c, (reassigning vs.index to compactvslots++ in markmode and otherwise sets cubetexture to the new vslot) when texture was used. More...
 
int compactvslots ()
 
 ICOMMAND (compactvslots,"",(),{extern SharedVar< int > nompedit;if(nompedit &&multiplayer()) return;int oldamount=vslots.length();compactvslots();Log.std->info("compacted virtual Slots (before: {0}, now: {1})", oldamount, vslots.length());allchanged();})
 
static void clampvslotoffset (VSlot &dst, Slot *slot=nullptr)
 
static void propagatevslot (VSlot &dst, const VSlot &src, int diff, bool edit=false)
 
void propagatevslot (VSlot *root, int changed)
 Apply changes to all following neighbors of root. More...
 
static void mergevslot (VSlot &dst, const VSlot &src, int diff, Slot *slot=nullptr)
 
void mergevslot (VSlot &dst, const VSlot &src, const VSlot &delta)
 
static bool comparevslot (const VSlot &dst, const VSlot &src, int diff)
 
void packvslot (vector< uchar > &buf, const VSlot &src)
 Pack a virtual Slot after it has been modified for broadcasting it to the other clients. More...
 
void packvslot (vector< uchar > &buf, int index)
 
void packvslot (vector< uchar > &buf, const VSlot *vs)
 
bool unpackvslot (ucharbuf &buf, VSlot &dst, bool delta)
 Unpack a virtual Slot modified by another client. More...
 
VSlotemptyvslot (Slot &owner)
 Wrapper around new VSlot to reuse unused dead vslots. More...
 
static VSlotclonevslot (const VSlot &src, const VSlot &delta)
 
 VARP (autocompactvslots, 0, 256, 0x10000)
 
VSloteditvslot (const VSlot &src, const VSlot &delta)
 Select a VSlot beeing src but having modifications based on delta (??) More...
 
static void fixinsidefaces (cube *c, const ivec &o, int size, int tex)
 
 ICOMMAND (fixinsidefaces,"i",(int *tex),{extern SharedVar< int > nompedit;if(noedit(true)||(nompedit &&multiplayer())) return;fixinsidefaces(worldroot, ivec(0, 0, 0), worldsize >> 1,*tex &&vslots.inrange(*tex)?*tex:DEFAULT_GEOM);allchanged();})
 
static void addglow (ImageData &c, ImageData &g, const vec &glowcolor)
 
static void mergespec (ImageData &c, ImageData &s, bool envmap=false)
 
static void mergedepth (ImageData &c, ImageData &z)
 
static void addname (vector< char > &key, Slot::Tex &t, bool combined=false, const char *prefix=nullptr)
 
void gencombinedname (vector< char > &name, int &texmask, Slot &s, Slot::Tex &t, int index, bool forceload)
 Generate a keyname to find a combined texture in the texture registry. More...
 
MSlotlookupmaterialslot (int index, bool load)
 
Slotlookupslot (int index, bool load)
 
VSlotlookupvslot (int index, bool load)
 
void linkslotshaders ()
 
void loadlayermasks ()
 
void cleanupslots ()
 
void cleanupvslots ()
 
void cleanupmaterialslots ()
 
int findslottex (const char *name)
 
void texture (char *type, char *name, int *rot, int *xoffset, int *yoffset, float *scale)
 
 COMMAND (texture,"ssiiif")
 
void autograss (char *name)
 
 COMMAND (autograss,"s")
 
void texscroll (float *scrollS, float *scrollT)
 
 COMMAND (texscroll,"ff")
 
void texoffset_ (int *xoffset, int *yoffset)
 
 COMMANDN (texoffset, texoffset_,"ii")
 
void texrotate_ (int *rot)
 
 COMMANDN (texrotate, texrotate_,"i")
 
void texscale (float *scale)
 
 COMMAND (texscale,"f")
 
void texlayer (int *layer, char *name, int *mode, float *scale)
 
 COMMAND (texlayer,"isif")
 
void texalpha (float *front, float *back)
 
 COMMAND (texalpha,"ff")
 
void texcolor (float *r, float *g, float *b)
 
 COMMAND (texcolor,"fff")
 

Variables

vector< VSlot * > vslots
 
vector< Slot * > slots
 
MSlot materialslots [(MATF_VOLUME|MATF_INDEX)+1]
 
Slot dummyslot
 
static int compactedvslots = 0
 
static int compactvslotsprogress = 0
 
static int clonedvslots = 0
 
static bool markingvslots = false
 
const struct slottex slottexs []
 

Class Documentation

struct slottex

Legacy texture slot loading.

Class Members
int id
const char * name

Function Documentation

static void addglow ( ImageData c,
ImageData g,
const vec glowcolor 
)
static

References ImageData::bpp, loopk, and readwritergbtex.

Referenced by Slot::loadthumbnail().

static void addname ( vector< char > &  key,
Slot::Tex t,
bool  combined = false,
const char *  prefix = nullptr 
)
static
static void assignvslot ( VSlot vs)
static

Set the vs.index according to compactvslots global counter.

References assignvslotlayer(), compactedvslots, and VSlot::index.

Referenced by assignvslotlayer(), compactvslot(), and compactvslots().

static void assignvslotlayer ( VSlot vs)
inlinestatic
void autograss ( char *  name)
static void clampvslotoffset ( VSlot dst,
Slot slot = nullptr 
)
static
void cleanupmaterialslots ( )
void cleanupslots ( )

References loopv, and slots.

Referenced by cleanuptextures().

void cleanupvslots ( )

References loopv, and vslots.

Referenced by cleanuptextures().

void clearslots ( )
static VSlot* clonevslot ( const VSlot src,
const VSlot delta 
)
static
COMMAND ( materialreset  ,
""   
)
COMMAND ( texture  ,
"ssiiif"   
)
COMMAND ( autograss  ,
"s"   
)
COMMAND ( texscroll  ,
"ff"   
)
COMMAND ( texscale  ,
"f"   
)
COMMAND ( texlayer  ,
"isif"   
)
COMMAND ( texalpha  ,
"ff"   
)
COMMAND ( texcolor  ,
"fff"   
)
COMMANDN ( texoffset  ,
texoffset_  ,
"ii"   
)
COMMANDN ( texrotate  ,
texrotate_  ,
"i"   
)
void compactvslot ( int &  index)

compacting mode: set index to compactvslots++ = vs.index, marking mode, just set vs.index

References assignvslot(), VSlot::index, markingvslots, and vslots.

Referenced by compacteditvslots().

void compactvslot ( VSlot vs)

References assignvslot(), and VSlot::index.

void compactvslots ( cube c,
int  n 
)

Loops through all n subcubes of c, (reassigning vs.index to compactvslots++ in markmode and otherwise sets cubetexture to the new vslot) when texture was used.

References allocnodes, assignvslot(), compactvslots(), compactvslotsprogress, f(), VSlot::index, loopi(), loopj, markingvslots, inexor::rpc::min(), renderprogress(), cube::texture, and vslots.

Referenced by compacteditvslots(), compactvslots(), editvslot(), and save_world().

int compactvslots ( )
static bool comparevslot ( const VSlot dst,
const VSlot src,
int  diff 
)
static
VSlot* editvslot ( const VSlot src,
const VSlot delta 
)

Select a VSlot beeing src but having modifications based on delta (??)

References allchanged(), clonedvslots, clonevslot(), compactvslots(), Slot::findvariant(), VSlot::slot, and vslots.

Referenced by remapvslot(), unpacktex(), and unpackvslots().

VSlot* emptyvslot ( Slot owner)

Wrapper around new VSlot to reuse unused dead vslots.

Warning
not threadsafe since it accesses slots and vslots globals.

References changed(), loopvrev, Slot::setvariantchain(), slots, and vslots.

Referenced by texture().

int findslottex ( const char *  name)

References slottex::id, loopi(), and slottexs.

Referenced by texture().

static void fixinsidefaces ( cube c,
const ivec o,
int  size,
int  tex 
)
static
void gencombinedname ( vector< char > &  name,
int &  texmask,
Slot s,
Slot::Tex t,
int  index,
bool  forceload 
)

Generate a keyname to find a combined texture in the texture registry.

References vector< T, MINSIZE >::add(), addname(), Slot::Tex::combined, Slot::findtexture(), TEX_DEPTH, TEX_DIFFUSE, TEX_NORMAL, TEX_SPEC, and Slot::Tex::type.

Referenced by Slot::combinetextures().

ICOMMAND ( texturereset  ,
"ii"  ,
(int *first, int *last)  ,
texturereset *,*  last 
)
ICOMMAND ( compactvslots  ,
""  ,
()  ,
{extern SharedVar< int > nompedit;if(nompedit &&multiplayer()) return;int oldamount=vslots.length();compactvslots();Log.std->info("compacted virtual Slots (before: {0}, now: {1})", oldamount, vslots.length());allchanged();}   
)
ICOMMAND ( fixinsidefaces  ,
"i"  ,
(int *tex)  ,
{extern SharedVar< int > nompedit;if(noedit(true)||(nompedit &&multiplayer())) return;fixinsidefaces(worldroot, ivec(0, 0, 0), worldsize >> 1,*tex &&vslots.inrange(*tex)?*tex:DEFAULT_GEOM);allchanged();}   
)
void linkslotshaders ( )
void loadlayermasks ( )

References loopv, and slots.

Referenced by calclight(), patchlight(), and previewblends().

MSlot& lookupmaterialslot ( int  index,
bool  load 
)
Slot& lookupslot ( int  index,
bool  load 
)
VSlot& lookupvslot ( int  index,
bool  load 
)
void materialreset ( )
static void mergedepth ( ImageData c,
ImageData z 
)
static

References readwritergbatex.

Referenced by Slot::combinetextures().

static void mergespec ( ImageData c,
ImageData s,
bool  envmap = false 
)
static

References ImageData::bpp, and readwritergbatex.

Referenced by Slot::combinetextures().

static void mergevslot ( VSlot dst,
const VSlot src,
int  diff,
Slot slot = nullptr 
)
static
void mergevslot ( VSlot dst,
const VSlot src,
const VSlot delta 
)
void packvslot ( vector< uchar > &  buf,
const VSlot src 
)
void packvslot ( vector< uchar > &  buf,
int  index 
)
void packvslot ( vector< uchar > &  buf,
const VSlot vs 
)
static void propagatevslot ( VSlot dst,
const VSlot src,
int  diff,
bool  edit = false 
)
static
void propagatevslot ( VSlot root,
int  changed 
)

Apply changes to all following neighbors of root.

Making it accordingly to roots vslot

Parameters
rootRoot of neighbours
changedincludes info about what changed

References VSlot::next, and propagatevslot().

void texalpha ( float *  front,
float *  back 
)
void texcolor ( float *  r,
float *  g,
float *  b 
)
void texlayer ( int *  layer,
char *  name,
int *  mode,
float *  scale 
)
void texoffset_ ( int *  xoffset,
int *  yoffset 
)
void texrotate_ ( int *  rot)
void texscale ( float *  scale)
void texscroll ( float *  scrollS,
float *  scrollT 
)
void texture ( char *  type,
char *  name,
int *  rot,
int *  xoffset,
int *  yoffset,
float *  scale 
)
void texturereset ( int  first,
int  num 
)

Resets all textures from the slots-stack.

Parameters
firstthe texturepos from whereon you want to reset
numthe number of slots you want to reset from thereon. All if 0 for example texturereset(0, 40); resets the first 40 textures

References game::allowedittoggle(), VSlot::changed, dummyslot, identflags, IDF_OVERRIDDEN, loopi(), VSlot::next, resetslotshader(), VSlot::slot, slots, Slot::variants, and vslots.

bool unpackvslot ( ucharbuf buf,
VSlot dst,
bool  delta 
)
VARP ( autocompactvslots  ,
,
256  ,
0x10000   
)

Variable Documentation

int clonedvslots = 0
static
int compactedvslots = 0
static

Referenced by assignvslot(), and compactvslots().

int compactvslotsprogress = 0
static

Referenced by compactvslots().

VSlot dummyvslot& dummyslot
bool markingvslots = false
static

Referenced by compactvslot(), and compactvslots().

MSlot materialslots[(MATF_VOLUME|MATF_INDEX)+1]
vector<Slot *> slots
const struct slottex slottexs[]
Initial value:
=
{
{ "c", TEX_DIFFUSE },
{ "u", TEX_UNKNOWN },
{ "d", TEX_DECAL },
{ "n", TEX_NORMAL },
{ "g", TEX_GLOW },
{ "s", TEX_SPEC },
{ "z", TEX_DEPTH },
{ "e", TEX_ENVMAP }
}
Definition: texture.hpp:20
Definition: texture.hpp:18
Definition: texture.hpp:19
Definition: texture.hpp:17
Definition: texture.hpp:21
Definition: texture.hpp:15
Definition: texture.hpp:16
Definition: texture.hpp:22

Referenced by findslottex().

vector<VSlot *> vslots