Browse Source

move sources into ./src/

Ivan Avdeev 7 years ago
parent
commit
18cfc45ce0
41 changed files with 3 additions and 1794 deletions
  1. 1 1
      .gitmodules
  2. 1 1
      compile.sh
  3. 1 1
      src/.ycm_extra_conf.py
  4. 0 460
      src/BSP.cpp
  5. 0 58
      src/BSP.h
  6. 0 156
      src/CloudAtlas.cpp
  7. 0 40
      src/CloudAtlas.h
  8. 0 149
      src/Entity.cpp
  9. 0 26
      src/Entity.h
  10. 0 155
      src/Materializer.cpp
  11. 0 27
      src/Materializer.h
  12. 0 0
      src/OpenSource.c
  13. 0 278
      src/OpenSource.cpp
  14. 0 59
      src/OpenSource.h
  15. 0 41
      src/ResRes.cpp
  16. 0 28
      src/ResRes.h
  17. 0 293
      src/VTF.cpp
  18. 0 21
      src/VTF.h
  19. 0 0
      src/ahash.h
  20. 0 0
      src/atlas.c
  21. 0 0
      src/atlas.h
  22. 0 0
      src/atto
  23. 0 0
      src/bsp.c
  24. 0 0
      src/bsp.h
  25. 0 0
      src/cache.c
  26. 0 0
      src/cache.h
  27. 0 0
      src/collection.c
  28. 0 0
      src/collection.h
  29. 0 0
      src/common.h
  30. 0 0
      src/dxt.c
  31. 0 0
      src/dxt.h
  32. 0 0
      src/filemap.c
  33. 0 0
      src/filemap.h
  34. 0 0
      src/libc.h
  35. 0 0
      src/material.c
  36. 0 0
      src/material.h
  37. 0 0
      src/mempools.h
  38. 0 0
      src/texture.c
  39. 0 0
      src/texture.h
  40. 0 0
      src/vbsp.h
  41. 0 0
      src/vtf.h

+ 1 - 1
.gitmodules

@@ -1,3 +1,3 @@
 [submodule "3p/atto"]
-	path = 3p/atto
+	path = src/atto
 	url = https://github.com/w23/atto.git

+ 1 - 1
compile.sh

@@ -10,7 +10,7 @@ DEBUG=
 RPI=
 RPI_ROOT=${RPI_ROOT:-'/opt/raspberry-pi'}
 
-SOURCES='OpenSource.c bsp.c atlas.c filemap.c collection.c material.c texture.c cache.c dxt.c'
+SOURCES='src/OpenSource.c src/bsp.c src/atlas.c src/filemap.c src/collection.c src/material.c src/texture.c src/cache.c src/dxt.c'
 WERROR='-Werror'
 CFLAGS="-D_GNU_SOURCE $CFLAGS"
 

+ 1 - 1
.ycm_extra_conf.py → src/.ycm_extra_conf.py

@@ -7,7 +7,7 @@ RPI_FLAGS = [
     '-DATTO_PLATFORM_RPI',
     '-D_POSIX_C_SOURCE=200809L',
     '-std=gnu99']
-COMMON_FLAGS = ['-Wall', '-Wextra', '-pedantic', '-std=c99', '-I.', '-I3p/atto']
+COMMON_FLAGS = ['-Wall', '-Wextra', '-pedantic', '-std=c99', '-I.', '-Iatto']
 
 def FlagsForFile(filename, **kwargs):
     flags = COMMON_FLAGS

+ 0 - 460
src/BSP.cpp

@@ -1,460 +0,0 @@
-#include <stddef.h> // offsetof
-#include <string.h>
-#include <vector>
-#include <map>
-#include <kapusha/core/Log.h>
-#include <kapusha/io/Stream.h>
-#include <kapusha/math/types.h>
-#include <kapusha/render/Render.h>
-#include <kapusha/render/Camera.h>
-#include "Materializer.h"
-#include "Entity.h"
-#include "CloudAtlas.h"
-#include "BSP.h"
-
-using namespace kapusha;
-
-namespace bsp {
-
-#pragma pack(push)
-#pragma pack(1)
-
-struct lump_t {
-  int offset;
-  int length;
-  int version;
-  int identifier;
-};
-
-enum lumpType {
-  lumpEntities = 0,
-  lumpTexdata = 2,
-  lumpVertexes = 3,
-  lumpTexinfo = 6,
-  lumpFaces = 7,
-  lumpLightmap = 8,
-  lumpEdges = 12,
-  lumpSurfedges = 13,
-  lumpTexStrdata = 43,
-  lumpTexStrtbl = 44,
-  lumpLightmapHDR = 53,
-  _lumpsCount = 64
-};
-
-struct header_t
-{
-  char magic[4];
-  int version;
-  lump_t lumps[_lumpsCount];
-  int	revision;
-};
-
-struct texinfo_t
-{
-  float textureVecs[2][4];
-  float lightmapVecs[2][4];
-  u32 flags;
-  u32 ref_texdata;
-};
-
-struct texdata_t
-{
-  vec3f reflectivity;
-  u32 nameStrtbl;
-  u32 width, height;
-  u32 vwidth, vheight;
-};
-
-struct face_t
-{
-  u16 ref_plane;
-  u8 plane_side;
-  u8 on_node;
-  u32 ref_surfedge;
-  u16 surfedges_count;
-  u16 ref_texinfo;
-  u16 ref_dispinfo;
-  u16 _unknown0; // ??
-  u8 lightstyles[4]; // ??
-  u32 ref_lightmap_offset;
-  float area;
-  s32 lightmapMins[2]; // ??
-  u32 lightmapSize[2]; // ??
-  u32 ref_original_face;
-  u16 primitives_count;
-  u16 ref_primitive;
-  u32 lightmap_smoothing_group; // ??
-};
-
-struct luxel_t
-{
-   u8 r, g, b;
-   s8 exp;
-};
-
-#pragma pack(pop)
-
-vec2f lightmapTexelAtVertex(vec3f v, const face_t &face,
-                            const texinfo_t* texinfo,
-                            rect2f atlas)
-{
-  vec2f lmap_size = vec2f(face.lightmapSize[0] + 1.f, face.lightmapSize[1] + 1.f);
-  const texinfo_t *t = &texinfo[face.ref_texinfo];
-  vec2f l(
-    (t->lightmapVecs[0][0]*v.x + t->lightmapVecs[0][1] * v.y + 
-     t->lightmapVecs[0][2]*v.z + t->lightmapVecs[0][3] - (float)face.lightmapMins[0]) / lmap_size.x,
-    1.f-(t->lightmapVecs[1][0]*v.x + t->lightmapVecs[1][1] * v.y + 
-         t->lightmapVecs[1][2]*v.z + t->lightmapVecs[1][3] - (float)face.lightmapMins[1]) / lmap_size.y);
-
-  return l * atlas.size() + atlas.bottomLeft();
-}
-
-} // namespace bsp
-
-BSP::BSP(void)
-  : parent_(0)
-  , relative_(0)
-  , translation_(0)
-  , shift_(0)
-  , contours_(0)
-{
-}
-
-BSP::~BSP(void)
-{
-  for(auto it = objects_.begin(); it != objects_.end(); ++it)
-    delete *it;
-  delete contours_;
-}
-
-bool BSP::load(StreamSeekable* stream, Materializer* materializer)
-{
-  //! \fixme check for errors
-  bsp::header_t header;
-  stream->copy(&header, sizeof header);
-
-  //! \fixme check format
-  //L("BSP magic: %c%c%c%c", header.magic[0], header.magic[1],
-  //  header.magic[2], header.magic[3]);
-  //L("BSP version: %d", header.version);
-  //L("BSP revision %d", header.revision);
-
-  if (header.version != 19)
-  {
-    L("BSP version: %d", header.version);
-    L("Still not sure how to load versions other than 19");
-    //return false;
-  }
-
-  // show lightmap info
-  bsp::luxel_t* lightmap;
-  int lmap_luxels;
-  {
-    const bsp::lump_t *lump_lmap = header.lumps + ((header.version < 20)? bsp::lumpLightmap : bsp::lumpLightmapHDR);
-    lmap_luxels = lump_lmap->length / sizeof(bsp::luxel_t);
-    //L("Lmap size: %d (%08x)", lump_lmap->length, lump_lmap->length);
-    stream->seek(lump_lmap->offset, StreamSeekable::ReferenceStart);
-    lightmap = new bsp::luxel_t[lmap_luxels];
-    stream->copy(lightmap, lump_lmap->length);
-
-    // pre-compute colors
-    for (int i = 0; i < lmap_luxels; ++i)
-    {
-      vec3i c = vec3i(lightmap[i].r, lightmap[i].g, lightmap[i].b);
-      if (lightmap[i].exp > 0)
-      {
-        c.x <<= lightmap[i].exp;
-        c.y <<= lightmap[i].exp;
-        c.z <<= lightmap[i].exp;
-      } else {
-        c.x >>= -lightmap[i].exp;
-        c.y >>= -lightmap[i].exp;
-        c.z >>= -lightmap[i].exp;
-      }
-
-#define CLAMP(f,min,max) (((f)<(min))?(min):((f)>(max)?(max):(f)))
-      c.x = CLAMP(c.x, 0, 255);
-      c.y = CLAMP(c.y, 0, 255);
-      c.z = CLAMP(c.z, 0, 255);
-#undef CLAMP
-
-      *reinterpret_cast<vec4<u8>*>(&lightmap[i]) = vec4<u8>(c);
-    }
-  }
-
-  // guess combined lightmap size
-  vec2i lmap_atlas_size(1);
-  for (;lmap_atlas_size.x * lmap_atlas_size.x < lmap_luxels; lmap_atlas_size.x <<= 1);
-  int lmap_min_height = lmap_luxels / lmap_atlas_size.x;
-  for (;lmap_atlas_size.y < lmap_min_height; lmap_atlas_size.y <<= 1);
-  CloudAtlas lmap_atlas(lmap_atlas_size);
-
-  // find linked maps in entities
-  {
-    const bsp::lump_t *lump_ent = header.lumps + bsp::lumpEntities;
-    stream->seek(lump_ent->offset, StreamSeekable::ReferenceStart);
-
-    for(;;)
-    {
-      Entity *ent = Entity::readNextEntity(stream);
-      if (!ent) break;
-
-      const std::string *classname = ent->getParam("classname");
-      if (classname)
-      {
-        if (*classname == "info_landmark")
-        {
-          KP_ASSERT(ent->getParam("targetname"));
-          KP_ASSERT(ent->getParam("origin"));
-          links_.landmarks[*ent->getParam("targetname")] = ent->getVec3Param("origin");
-        } else if (*classname == "trigger_changelevel")
-        {
-          KP_ASSERT(ent->getParam("landmark"));
-          KP_ASSERT(ent->getParam("map"));
-          links_.maps[*ent->getParam("map")] = *ent->getParam("landmark");
-        }
-      }
-
-      delete ent;
-    }
-  }
-
-  // load vertices
-  vec3f *vertices;
-  int num_vertices;
-  {
-    const bsp::lump_t *lump_vtx = header.lumps + bsp::lumpVertexes;
-    num_vertices = lump_vtx->length / sizeof(vec3f);
-    vertices = new vec3f[num_vertices];
-    //L("Vertices: %d", lump_vtx->length / 12);
-    stream->seek(lump_vtx->offset, StreamSeekable::ReferenceStart);
-    stream->copy(vertices, lump_vtx->length);
-  }
-
-  // preload surfedges
-  // load edges
-  const bsp::lump_t *lump_edges = header.lumps + bsp::lumpEdges;
-  int num_edges = lump_edges->length / 4;
-  //L("Edges: %d", num_edges);
-  stream->seek(lump_edges->offset, StreamSeekable::ReferenceStart);
-  struct edge_t {
-    u16 a, b;
-  } *edges = new edge_t[num_edges];
-  stream->copy(edges, lump_edges->length);
-
-  // load surfedges
-  const bsp::lump_t *lump_surfedges = header.lumps + bsp::lumpSurfedges;
-  int num_surfedges = lump_surfedges->length / 4;
-  //L("Surfedges: %d", num_surfedges);
-  stream->seek(lump_surfedges->offset, StreamSeekable::ReferenceStart);
-  int *surfedges_i = new int[num_surfedges];
-  u16 *surfedges = new u16[num_surfedges];
-  stream->copy(surfedges_i, num_surfedges * 4);
-  for(int i = 0; i < num_surfedges; ++i)
-    if (surfedges_i[i] >= 0)
-      surfedges[i] = edges[surfedges_i[i]].a;
-    else 
-      surfedges[i] = edges[-surfedges_i[i]].b;
-
-  // load texinfo
-  const bsp::lump_t *lump_texinfo = header.lumps + bsp::lumpTexinfo;
-  int num_texinfo = lump_texinfo->length / sizeof(bsp::texinfo_t);
-  //L("Texinfos: %d", num_texinfo);
-  stream->seek(lump_texinfo->offset, StreamSeekable::ReferenceStart);
-  bsp::texinfo_t *texinfo = new bsp::texinfo_t[num_texinfo];
-  stream->copy(texinfo, lump_texinfo->length);
-
-  // load texdata
-  const bsp::lump_t *lump_texdata = header.lumps + bsp::lumpTexdata;
-  int num_texdata = lump_texdata->length / sizeof(bsp::texdata_t);
-  //L("Texdatas: %d", num_texdata);
-  stream->seek(lump_texdata->offset, StreamSeekable::ReferenceStart);
-  bsp::texdata_t *texdata = new bsp::texdata_t[num_texdata];
-  stream->copy(texdata, lump_texdata->length);
-
-  // load texstrdata
-  const bsp::lump_t *lump_texstrdata = header.lumps + bsp::lumpTexStrdata;
-  //L("Texstrdata: %d", lump_texstrdata->length);
-  stream->seek(lump_texstrdata->offset, StreamSeekable::ReferenceStart);
-  char* texstrdata = new char[lump_texstrdata->length];
-  stream->copy(texstrdata, lump_texstrdata->length);
-
-  // load texstrtbl
-  const bsp::lump_t *lump_texstrtbl = header.lumps + bsp::lumpTexStrtbl;
-  //L("Texstrtbl: %d", lump_texstrtbl->length / 4);
-  stream->seek(lump_texstrtbl->offset, StreamSeekable::ReferenceStart);
-  int* texstrtbl = new int[lump_texstrtbl->length / 4];
-  stream->copy(texstrtbl, lump_texstrtbl->length);
-
-  // load faces
-  const bsp::lump_t *lump_faces = header.lumps + bsp::lumpFaces;
-  int num_faces = lump_faces->length / sizeof(bsp::face_t);
-  //L("Faces: %d", num_faces);
-  stream->seek(lump_faces->offset, StreamSeekable::ReferenceStart);
-
-  struct MapVertex {
-    vec3f vertex;
-    vec2f tc_lightmap;
-
-    MapVertex() {}
-    MapVertex(vec3f _vertex, vec2f _lightmap)
-      : vertex(_vertex), tc_lightmap(_lightmap) {}
-  };
-  std::vector<MapVertex> tmp_vtx;
-  std::vector<u16> tmp_idx;
-  std::vector<u16> tmp_idx_cont;
-  for (int i = 0; i < num_faces; ++i)
-  {
-    bsp::face_t face;
-    stream->copy(&face, sizeof(bsp::face_t));
-
-    /*L("Face %d", i);
-    L("\tedges: %d->%d", face.ref_surfedge, face.ref_surfedge+face.surfedges_count);
-    L("\tlightmap: %d", face.ref_lightmap_offset);
-    L("\tstyles: %d %d %d %d",
-      face.lightstyles[0], face.lightstyles[1],
-      face.lightstyles[2], face.lightstyles[3]);
-    L("\tluxels: %d x %d", face.lightmapSize[0], face.lightmapSize[1]);
-    L("\tluxels (mins ??): %d x %d", face.lightmapMins[0], face.lightmapMins[1]);
-    */
-
-    //if (face.ref_lightmap_offset < 4) continue;
-    //if (face.ref_texinfo < 0) continue;
-    //if (texinfo[face.ref_texinfo].ref_texdata == -1) continue;
-
-    if (texinfo[face.ref_texinfo].flags & 0x401) {
-      int tex_table_index = texdata[texinfo[face.ref_texinfo].ref_texdata].nameStrtbl;
-      KP_ASSERT(tex_table_index < lump_texstrtbl->length / 4);
-      int tex_data_index = texstrtbl[tex_table_index];
-      KP_ASSERT(tex_data_index < lump_texstrdata->length);
-      //L("%d %d %08x %s", i, face.on_node, texinfo[face.ref_texinfo].flags, texstrdata + tex_data_index);
-      if (strstr(texstrdata + tex_data_index, "TOOL"))
-        continue;
-    }
-
-    vec2i lmap_size = vec2i(1, 1);
-    static u32 white = 0xffffffff;
-    const void *luxels = &white;
-    if (face.ref_lightmap_offset/4 < (unsigned)lmap_luxels)
-    {
-      lmap_size = vec2i(face.lightmapSize[0] + 1, face.lightmapSize[1] + 1);
-      luxels = &lightmap[face.ref_lightmap_offset / 4];
-    }
-    
-    rect2f lmap_region = lmap_atlas.addImage(lmap_size, luxels);
-    KP_ASSERT(lmap_region.bottom() >= 0.f);
-
-    int index_shift = static_cast<int>(tmp_vtx.size());
-
-    vec3f vtx = vertices[surfedges[face.ref_surfedge]];
-    tmp_vtx.push_back(MapVertex(vtx, bsp::lightmapTexelAtVertex(vtx, face, texinfo, lmap_region)));
-    
-    vtx = vertices[surfedges[face.ref_surfedge+1]];
-    tmp_vtx.push_back(MapVertex(vtx, bsp::lightmapTexelAtVertex(vtx, face, texinfo, lmap_region)));
-
-    edge_t *e = &edges[abs(surfedges_i[face.ref_surfedge])];
-    if (e->a != e->b)
-    {
-      tmp_idx_cont.push_back(index_shift + 0);
-      tmp_idx_cont.push_back(index_shift + 1);
-      e->a = e->b; // mark as drawn
-    }
-    
-    for (int j = 2; j < face.surfedges_count; ++j)
-    {
-      vtx = vertices[surfedges[face.ref_surfedge + j]];
-      tmp_vtx.push_back(MapVertex(vtx, bsp::lightmapTexelAtVertex(vtx, face, texinfo, lmap_region)));
-
-      tmp_idx.push_back(index_shift + 0);
-      tmp_idx.push_back(index_shift + j-1);
-      tmp_idx.push_back(index_shift + j);
-
-      // store contours
-      edge_t *e = &edges[abs(surfedges_i[face.ref_surfedge + j])];
-      if (e->a != e->b)
-      {
-        tmp_idx_cont.push_back(index_shift + j-1);
-        tmp_idx_cont.push_back(index_shift + j);
-        e->a = e->b;
-      }
-    }
-  }
-  L("Map: vertices %d, indices %d", tmp_vtx.size(), tmp_idx.size());
-  if (tmp_vtx.size() > 65535)
-    L("WARNING: total vertices size exceeds 64k: %d", tmp_vtx.size());
-
-  delete texstrtbl;
-  delete texstrdata;
-  delete texdata;
-  delete texinfo;
-  delete surfedges_i;
-  delete edges;
-  delete vertices;
-  delete surfedges;
-  delete lightmap;
-  
-  // common
-  Buffer *attribs_buffer = new Buffer;
-  attribs_buffer->load(&tmp_vtx[0], tmp_vtx.size() * sizeof(MapVertex));
-
-  { // map geometry
-    Buffer *index_buffer = new Buffer;
-    index_buffer->load(&tmp_idx[0], tmp_idx.size() * sizeof(tmp_idx[0]));
-
-    Batch* batch = new Batch();
-    batch->setMaterial(materializer->loadMaterial("__lightmap_only"));
-    batch->setAttribSource("av4_vertex", attribs_buffer, 3, 0, sizeof(MapVertex));
-    batch->setAttribSource("av2_lightmap", attribs_buffer, 2, offsetof(MapVertex, tc_lightmap), sizeof(MapVertex));
-    batch->setGeometry(Batch::GeometryTriangleList, 0, tmp_idx.size(), Batch::IndexU16, index_buffer);
-    objects_.push_back(new Object(batch));
-
-    lightmap_ = lmap_atlas.texture();
-  }
-
-  { // contours
-    Buffer *index_buffer = new Buffer;
-    index_buffer->load(&tmp_idx_cont[0], tmp_idx_cont.size() * sizeof(tmp_idx_cont[0]));
-
-    Batch* batch = new Batch();
-    batch->setMaterial(materializer->loadMaterial("__white"));
-    batch->setAttribSource("av4_vertex", attribs_buffer, 3, 0, sizeof(MapVertex));
-    batch->setGeometry(Batch::GeometryLineList, 0, tmp_idx_cont.size(), Batch::IndexU16, index_buffer);
-    contours_ = new Object(batch);
-  }
-
-  return true;
-}
-
-void BSP::draw(const kapusha::Camera& cam) const
-{
-  for(auto it = objects_.begin(); it != objects_.end(); ++it)
-  {
-    (*it)->getBatch()->getMaterial()->setUniform("uv4_trans", vec4f(translation_));
-    (*it)->getBatch()->getMaterial()->setTexture("us2_lightmap", lightmap_);
-    (*it)->draw(cam.getView(), cam.getProjection());
-  }
-}
-
-void BSP::drawContours(const kapusha::Camera& cam) const
-{
-  if (contours_)
-  {
-    contours_->getBatch()->getMaterial()->setUniform("uv4_trans", vec4f(translation_));
-    contours_->draw(cam.getView(), cam.getProjection());
-  }
-}
-
-void BSP::setParent(const BSP* parent, vec3f relative)
-{
-  parent_ = parent;
-  relative_ = relative;
-  updateShift(shift_);
-}
-
-void BSP::updateShift(vec3f shift)
-{
-  shift_ = shift;
-  translation_ = relative_ + shift_;
-  if (parent_)
-    translation_ += parent_->translation();
-}

+ 0 - 58
src/BSP.h

@@ -1,58 +0,0 @@
-#pragma once
-
-#include <vector>
-#include <map>
-#include <memory>
-
-
-namespace kapusha {
-  class StreamSeekable;
-  class Camera;
-  class Object;
-  class Texture;
-  class Batch;
-}
-
-using kapusha::StreamSeekable;
-using kapusha::Object;
-using kapusha::Texture;
-
-class Materializer;
-
-class BSP
-{
-public:
-  BSP(void);
-  ~BSP(void);
-
-  bool load(StreamSeekable *stream, Materializer* materializer);
-
-  void setParent(const BSP* parent, kapusha::vec3f relative);
-  void updateShift(kapusha::vec3f shift);
-  const kapusha::vec3f& shift() const { return shift_; }
-  const kapusha::vec3f& translation() const { return translation_; }
-  
-  void draw(const kapusha::Camera&) const;
-  void drawContours(const kapusha::Camera&) const;
-
-public:
-  struct MapLink {
-    std::map<std::string, kapusha::vec3f> landmarks;
-    std::map<std::string, std::string> maps;
-  };
-  const MapLink& getMapLinks() const { return links_; }
-
-private:
-  const BSP *parent_;
-  kapusha::vec3f relative_;
-  kapusha::vec3f translation_;
-  kapusha::vec3f shift_;
-  MapLink links_;
-
-  std::vector<Object*> objects_;
-  Texture *lightmap_;
-  
-  Object *contours_;
-
-  //kapusha::Batch *tstmp;
-};

+ 0 - 156
src/CloudAtlas.cpp

@@ -1,156 +0,0 @@
-#include <string.h>
-#include <kapusha/render/Texture.h>
-#include "CloudAtlas.h"
-
-CloudAtlas::CloudAtlas(kapusha::vec2i size)
-  : size_(size)
-  , pix2tex_(1.f / size.x, 1.f / size.y)
-  , pixels_(new lmap_texel_t[size_.x * size_.y])
-{
-  for (int i = 0; i < (size_.x * size_.y); ++i)
-#if LIGHTMAP_FORMAT == 1
-    pixels_[i] = 0xf800;
-#else
-    *reinterpret_cast<kapusha::vec4<kapusha::u8>*>(pixels_+i) = 
-      kapusha::vec4<kapusha::u8>(255, 0, 0, 0);
-#endif
-  root_ = new Node(kapusha::rect2i(size_));
-}
-
-CloudAtlas::~CloudAtlas(void)
-{
-  for(Node *n = root_; n != 0;)
-  {
-    Node *next = n->next;
-    delete n;
-    n = next;
-  }
-
-  delete pixels_;
-}
-
-kapusha::Texture *CloudAtlas::texture() const
-{
-  kapusha::Texture *ret = new kapusha::Texture();
-#if LIGHTMAP_FORMAT == 1
-  kapusha::Texture::Meta::PixelFormat format = kapusha::Texture::Meta::RGB565;
-//! \todo #elif LIGHTMAP_FORMAT == 2 
-// ETC1
-#else
-  kapusha::Texture::Meta::PixelFormat format = kapusha::Texture::Meta::RGBA8888;
-#endif
-  ret->upload(kapusha::Texture::Meta(size_, format),
-              pixels_);
-  return ret;
-}
-
-kapusha::rect2f CloudAtlas::addImage(kapusha::vec2i size, const void *data)
-{
-  for(Node *n = root_;;)
-  {
-    if (n->insert(size))
-    {
-      kapusha::rect2i r = n->rect;
-      KP_ASSERT(r.size() == size);
-
-      if (n == root_)
-        root_ = n->next;
-      if (n->prev)
-        n->prev->next = n->next;
-      if (n->next)
-        n->next->prev = n->prev;
-      delete n;
-
-      const kapusha::vec4<kapusha::u8> *p_in =
-        reinterpret_cast<const kapusha::vec4<kapusha::u8>*>(data);
-      lmap_texel_t *p_out = pixels_ + r.bottom() * size_.x + r.left();
-      for (int y = 0; y < size.y; ++y, p_out += size_.x, p_in += size.x)
-      {
-#if LIGHTMAP_FORMAT == 1
-        for (int x = 0; x < size.x; ++x)
-          p_out[x] =
-            ((p_in[x].x&0xf8) << 8) |
-            ((p_in[x].y&0xfc) << 3) |
-            (p_in[x].z >> 3);
-#else
-        memcpy(p_out, p_in, sizeof(lmap_texel_t) * size.x);
-#endif
-      }
-
-      return kapusha::rect2f(kapusha::vec2f(r.left()+.5f, r.top()) * pix2tex_,
-                          kapusha::vec2f(r.right(), r.bottom()+.5f) * pix2tex_);
-    }
-
-    if (!n->next)
-      break;
-
-    // detect unlink
-    if (n->next->prev != n)
-    {
-      if (n == root_)
-        root_ = n->next;
-      Node *t = n->next;
-      if (n->prev)
-        n->prev->next = t;
-      if (n->next)
-        n->next->prev = n->prev;
-      delete n;
-      n = t;
-    } else {
-      n = n->next;
-    }
-  }
-
-  return kapusha::rect2f(-1.f);
-}
-
-bool CloudAtlas::Node::insert(kapusha::vec2i size)
-{
-  // early check whether it'll fit
-  if (rect.width() < size.x || rect.height() < size.y)
-    return false;
-  
-  // if it fits exactly, return it
-  if (rect.size() == size)
-    return true;
-
-  // split
-  kapusha::vec2i diff = rect.size() - size;
-  kapusha::rect2i r[2];
-  if (diff.x > diff.y)
-  {
-    r[0] = kapusha::rect2i(rect.left(), rect.bottom(),
-                        rect.right() - diff.x, rect.top());
-    r[1] = kapusha::rect2i(rect.right() - diff.x, rect.bottom(),
-                        rect.right(), rect.top());
-  } else {
-    r[0] = kapusha::rect2i(rect.left(), rect.bottom(),
-                        rect.right(), rect.top() - diff.y);
-    r[1] = kapusha::rect2i(rect.left(), rect.top() - diff.y,
-                        rect.right(), rect.top());
-  }
-
-  // the insertage
-  Node *newn[2];
-  newn[0] = new Node(r[0]);
-  newn[1] = new Node(r[1]);
-
-  newn[0]->next = newn[1];
-  newn[1]->prev = newn[0];
-
-  if (prev)
-  {
-    prev->next = newn[0];
-    newn[0]->prev = prev;
-  }
-
-  if (next)
-  {
-    next->prev = newn[1];
-    newn[1]->next = next;
-  }
-
-  next = newn[0];
-
-  return false;
-}

+ 0 - 40
src/CloudAtlas.h

@@ -1,40 +0,0 @@
-#pragma once
-#include <kapusha/core/Core.h>
-#include <kapusha/math/types.h>
-
-namespace kapusha {
-  class Texture;
-}
-
-#if LIGHTMAP_FORMAT == 1
-typedef kapusha::u16 lmap_texel_t;
-#else
-typedef kapusha::u32 lmap_texel_t;
-#endif
-
-class CloudAtlas
-{
-public:
-  CloudAtlas(kapusha::vec2i size);
-  ~CloudAtlas(void);
-
-  kapusha::rect2f addImage(kapusha::vec2i size, const void *p);
-  kapusha::Texture *texture() const;
-
-private:
-  kapusha::vec2i size_;
-  kapusha::vec2f pix2tex_;
-  lmap_texel_t *pixels_;
-
-  struct Node {
-    kapusha::rect2i rect;
-    Node *next, *prev;
-
-    Node(kapusha::rect2i _rect)
-      : rect(_rect)
-    { next = prev = 0; }
-    bool insert(kapusha::vec2i size);
-  };
-  Node *root_;
-};
-

+ 0 - 149
src/Entity.cpp

@@ -1,149 +0,0 @@
-#include <sstream>
-#include <kapusha/core/Log.h>
-#include "Entity.h"
-
-Entity::Entity(void)
-{
-}
-
-
-Entity::~Entity(void)
-{
-}
-
-off_t streamSkipSpacesUntilAfterChars(kapusha::Stream* stream, const char* chars)
-{
-  off_t ret = -1;
-  while(stream->error_ == kapusha::Stream::ErrorNone)
-  {
-    for(; stream->cursor_ < stream->end_; ++stream->cursor_)
-    {
-      if (ret != -1)
-        return ret;
-
-      if (!isspace(*stream->cursor_))
-      {
-        for(const char* p = chars; *p != 0; ++p)
-          if (*stream->cursor_ == *p)
-          {
-            // do one more cycle to reload 
-            ret = p - chars;
-            break;
-          }
-        if (ret == -1)
-          return -1;
-      }
-    }
-    stream->refill();
-  }
-
-  return ret;
-}
-
-off_t streamExtractUntilAfterChars(kapusha::Stream* stream, char end,
-                                         char* out, int outmax)
-{
-  char *p = out;
-  while(stream->error_ == kapusha::Stream::ErrorNone)
-  {
-    for(; stream->cursor_ < stream->end_; ++stream->cursor_)
-    {
-      if (*stream->cursor_ == end)
-      {
-          ++stream->cursor_;
-          *p = 0;
-          return p - out;
-      }
-      *p++ = *stream->cursor_;
-      KP_ASSERT(p < (out + outmax));
-    }
-    stream->refill();
-  }
-  return -1;
-}
-
-Entity* Entity::readNextEntity(kapusha::Stream* stream)
-{
-  if (0 != streamSkipSpacesUntilAfterChars(stream, "{"))
-    return 0;
-
-  char key[32];
-  char value[1024];
-  
-  Entity *ret = new Entity();
-
-  for(;;)
-  {
-    off_t chidx = streamSkipSpacesUntilAfterChars(stream, "\"}");
-    if (chidx == 1)
-      return ret;
-
-    if (chidx == -1)
-      break;
-    
-    if (-1 == streamExtractUntilAfterChars(stream, '"', key, sizeof key))
-      break;
-
-    if (-1 == streamSkipSpacesUntilAfterChars(stream, "\""))
-      break;
-
-    if (-1 == streamExtractUntilAfterChars(stream, '"', value, sizeof value))
-      break;
-
-    ret->params_[key] = value;
-  }
-
-  delete ret;
-  return 0;
-}
-
-const std::string* Entity::getParam(const std::string& name) const
-{
-
-  auto entry = params_.find(name);
-  if (entry == params_.end())
-    return 0;
-
-  return &entry->second;
-}
-
-kapusha::vec3f Entity::getVec3Param(const std::string& name) const
-{
-  auto entry = params_.find(name);
-  if (entry == params_.end())
-    return kapusha::vec3f();
-
-  kapusha::vec3f value;
-  std::stringstream ss(entry->second);
-  ss >> value.x;
-  ss >> value.y;
-  ss >> value.z;
-
-  return value;
-}
-
-kapusha::vec4f Entity::getVec4Param(const std::string& name) const
-{
-  auto entry = params_.find(name);
-  if (entry == params_.end())
-    return kapusha::vec4f();
-
-  kapusha::vec4f value;
-  std::stringstream ss(entry->second);
-  ss >> value.x;
-  ss >> value.y;
-  ss >> value.z;
-  ss >> value.w;
-
-  return value;
-}
-
-void Entity::print() const
-{
-  L("Entity {");
-  for(auto it = params_.begin(); it != params_.end(); ++it)
-  {
-    L("\t%s: %s", it->first.c_str(), it->second.c_str());
-  }
-  L("}");
-}

+ 0 - 26
src/Entity.h

@@ -1,26 +0,0 @@
-#pragma once
-#include <string>
-#include <map>
-#include <kapusha/io/Stream.h>
-#include <kapusha/math/types.h>
-
-class Entity
-{
-public:
-  ~Entity(void);
-
-  static Entity* readNextEntity(kapusha::Stream* stream);
-
-  const std::map<std::string, std::string>& params() { return params_; }
-
-  const std::string* getParam(const std::string& name) const;
-  kapusha::vec3f getVec3Param(const std::string& name) const;
-  kapusha::vec4f getVec4Param(const std::string& name) const;
-
-  void print() const;
-
-private:
-  Entity(void);
-  std::map<std::string, std::string> params_;
-};
-

+ 0 - 155
src/Materializer.cpp

@@ -1,155 +0,0 @@
-#include <kapusha/core/Core.h>
-#include <kapusha/io/Stream.h>
-#include <kapusha/render/Render.h>
-#include "ResRes.h"
-#include "VTF.h"
-#include "Materializer.h"
-
-static const char* shader_vertex =
-#if KAPUSHA_GLES
-  "precision mediump float;\n"
-#endif
-  "uniform mat4 um4_view, um4_proj;\n"
-  "uniform vec4 uv4_trans;\n"
-  "uniform vec2 uv2_texscale;\n"
-  "attribute vec4 av4_vtx, av4_tex;\n"
-  "varying vec2 vv2_tex;\n"
-  "void main(){\n"
-    "gl_Position = um4_proj * um4_view * (av4_vtx + uv4_trans);\n"
-    "vv2_tex = av4_tex.xy * uv2_texscale;\n"
-  "}"
-;
-
-static const char* shader_fragment =
-#if KAPUSHA_GLES
-  "precision mediump float;\n"
-#endif
-  "uniform sampler2D us2_texture;\n"
-  "varying vec2 vv2_tex;\n"
-  "void main(){\n"
-    "gl_FragColor = texture2D(us2_texture, vv2_tex);\n"
-  "}"
-;
-
-static const char* shader_vertex_lightmap =
-#if KAPUSHA_GLES
-  "precision mediump float;\n"
-#endif
-  "uniform mat4 um4_view, um4_proj;\n"
-  "uniform vec4 uv4_trans;\n"
-  "attribute vec4 av4_vertex;\n"
-  "attribute vec2 av2_lightmap;\n"
-  "varying vec2 vv2_lightmap;\n"
-  "void main(){\n"
-    "gl_Position = um4_proj * um4_view * (av4_vertex + uv4_trans);\n"
-    "vv2_lightmap = av2_lightmap;\n"
-  "}"
-;
-
-static const char* shader_fragment_lightmap =
-#if KAPUSHA_GLES
-  "precision mediump float;\n"
-#endif
-  "uniform sampler2D us2_lightmap;\n"
-  "varying vec2 vv2_lightmap;\n"
-  "void main(){\n"
-    "gl_FragColor = texture2D(us2_lightmap, vv2_lightmap) + vec4(.02);\n"
-  "}"
-;
-
-static const char* shader_vertex_white =
-#if KAPUSHA_GLES
-  "precision mediump float;\n"
-#endif
-  "uniform mat4 um4_view, um4_proj;\n"
-  "uniform vec4 uv4_trans;\n"
-  "attribute vec4 av4_vertex;\n"
-  "void main(){\n"
-    "gl_Position = um4_proj * um4_view * (av4_vertex + uv4_trans);\n"
-  "}"
-;
-
-static const char* shader_fragment_white =
-#if KAPUSHA_GLES
-  "precision mediump float;\n"
-#endif
-  "void main(){\n"
-    "gl_FragColor = vec4(1.);\n"
-  "}"
-;
-
-Materializer::Materializer(const ResRes& resources)
-  : resources_(resources)
-{
-  UBER_SHADER1111_ = new kapusha::Program(shader_vertex,
-                                          shader_fragment);
-}
-
-Materializer::~Materializer(void)
-{
-}
-
-kapusha::Material* Materializer::loadMaterial(const char *name_raw)
-{
-  std::string name(name_raw);
-
-  //! \fixme broken atm
-  KP_ASSERT(name != "__BSP_edge");
-
-  auto fm = cached_materials_.find(name);
-  if (fm != cached_materials_.end())
-    return fm->second;
-
-  if (name == "__lightmap_only")
-  {
-    GL_ASSERT
-    kapusha::Program *prog = new kapusha::Program(shader_vertex_lightmap,
-                                                  shader_fragment_lightmap);
-    GL_ASSERT
-    kapusha::Material* mat = new kapusha::Material(prog);
-    GL_ASSERT
-    cached_materials_[name] = mat;
-    return mat;
-  } else if (name == "__white")
-  {
-    kapusha::Program *prog = new kapusha::Program(shader_vertex_white,
-                                                  shader_fragment_white);
-    kapusha::Material* mat = new kapusha::Material(prog);
-    cached_materials_[name] = mat;
-    return mat;
-  }
-
-#if 0 // texture support is no more
-  kapusha::StreamSeekable* restream = resources_.open(name.c_str(), ResRes::ResourceTexture);
-  kapusha::Material* mat = new kapusha::Material(UBER_SHADER1111_);
-  if (restream)
-  {
-    VTF tex;
-    kapusha::Texture *texture = tex.load(*restream);
-    if (texture)
-    {
-      mat->setUniform("uv2_texscale",
-                      kapusha::vec2f(1.f / tex.size().x, 1.f / tex.size().y));
-      mat->setTexture("us2_texture", texture);
-    }
-    delete restream;
-  }
-  
-  cached_materials_[name] = mat;
-#endif
-
-  KP_ASSERT(!"true materials are not supported");
-
-  return 0;
-
-}
-
-void Materializer::print() const
-{
-  L("Cached materials:");
-  int i = 0;
-  for (auto it = cached_materials_.begin();
-    it != cached_materials_.end(); ++it, ++i)
-    L("\t%d: %s", i, it->first.c_str());
-  L("TOTAL: %d", cached_materials_.size());
-}

+ 0 - 27
src/Materializer.h

@@ -1,27 +0,0 @@
-#pragma once
-#include <string>
-#include <map>
-
-namespace kapusha {
-  class Program;
-  class Material;
-}
-
-class ResRes;
-
-class Materializer
-{
-public:
-  Materializer(const ResRes& resources);
-  ~Materializer(void);
-
-  kapusha::Material* loadMaterial(const char* name);
-
-  void print() const;
-
-private:
-  const ResRes& resources_;
-  kapusha::Program *UBER_SHADER1111_;
-  std::map<std::string, kapusha::Material*> cached_materials_;
-};
-

+ 0 - 0
OpenSource.c → src/OpenSource.c


+ 0 - 278
src/OpenSource.cpp

@@ -1,278 +0,0 @@
-#include <kapusha/core/Log.h>
-#include <kapusha/math/types.h>
-#include <kapusha/render/Render.h>
-#include <kapusha/io/StreamFile.h>
-#include "Materializer.h"
-#include "BSP.h"
-#include "OpenSource.h"
-
-OpenSource::OpenSource(
-  const char *path,
-  const char *file,
-  int depth)
-: resources_(path)
-, depth_(depth)
-, camera_(kapusha::vec3f(0,10,0), kapusha::vec3f(0), kapusha::vec3f(0,0,1), 60.f, 1.7, 10.f, 100000.f)
-, forward_speed_(0), right_speed_(0), pitch_speed_(0), yaw_speed_(0)
-, selection_(0)
-, show_selection_(false)
-, mouselook_(false)
-{
-  maps_to_load_.push_back(file);
-}
-
-OpenSource::~OpenSource(void)
-{
-}
-
-void OpenSource::init(kapusha::IViewportController* viewctrl)
-{
-  viewctrl_ = viewctrl;
-  render_ = new kapusha::Render;
-
-  Materializer materializer(resources_);
-
-  while (depth_ > 0 && !maps_to_load_.empty())
-  {
-    //L("maps to load left %d %d", maps_to_load_.size(), depth_);
-
-    std::string map = maps_to_load_.front();
-    maps_to_load_.pop_front();
-
-    L("Loading map %s", map.c_str());
-
-    kapusha::StreamSeekable *stream = resources_.open(map.c_str(), ResRes::ResourceMap);
-    if (!stream)
-    {
-      L("cannot load map %s", map.c_str());
-      continue;
-    }
-    BSP *bsp = new BSP;
-    KP_ENSURE(bsp->load(stream, &materializer));
-    delete stream;
-
-    //! \hack inject c1a0c link to previous map
-    BSP::MapLink hacklink;
-    if (map == "c1a0c")
-    {
-      hacklink = bsp->getMapLinks();
-      hacklink.maps["c1a0b"] = "c1a0btoc";
-      hacklink.landmarks["c1a0btoc"] = kapusha::vec3f(2052.f, 864.f, 566.f);
-    }
-    const BSP::MapLink& link = hacklink.landmarks.empty() ? bsp->getMapLinks() : hacklink;
-
-    {
-      bool link_found = false;
-      for(auto ref = link.maps.begin(); ref != link.maps.end(); ++ref)
-      {
-        auto refmark = link.landmarks.find(ref->second);
-        KP_ASSERT(refmark != link.landmarks.end());
-        L("\t links to %s via landmark \"%s\" (%f, %f, %f)",
-          ref->first.c_str(), refmark->first.c_str(),
-          refmark->second.x, refmark->second.y, refmark->second.z);
-        
-        auto found = levels_.find(ref->first);
-        if (found != levels_.end())
-        {
-          if (!link_found)
-          {
-            auto landmark = found->second->getMapLinks().landmarks.find(ref->second);
-            KP_ASSERT(landmark != found->second->getMapLinks().landmarks.end());
-
-            bsp->setParent(found->second, landmark->second - refmark->second);
-            /*L("%s (%f, %f, %f) links to %s (%f, %f, %f)",
-              map.c_str(), minemark->second.x, minemark->second.y, minemark->second.z,
-              ref->first.c_str(), landmark->second.x, landmark->second.y, landmark->second.z);*/
-            link_found = true;
-          }
-        } else {
-          if (map != ref->first && 
-              std::find(maps_to_load_.begin(),
-                        maps_to_load_.end(), ref->first) == maps_to_load_.end())
-          {
-            if (enabled_maps_.empty() || enabled_maps_.count(ref->first))
-              maps_to_load_.push_back(ref->first);
-          }
-        }
-      }
-
-      if (!link_found && !levels_.empty())
-        L("WARNING! %s doesn't link to any existing map! This map will begin from (0, 0, 0)", map.c_str());
-    }
-
-    levels_[map] = bsp;
-    levelsv_.push_back(bsp);
-    depth_--;
-  }
-
-  {
-    materializer.print();
-  }
-
-  {
-    L("List of all loaded maps:");
-    int i = 0;
-    for (auto it = levels_.begin(); it != levels_.end(); ++it, ++i)
-      L("%d: %s (%f, %f, %f)", i, it->first.c_str(),
-        it->second->translation().x, it->second->translation().y, it->second->translation().z);
-  }
-
-  render_->cullFace().on();
-  render_->depthTest().on();
-  glFrontFace(GL_CW);
-}
-
-void OpenSource::resize(kapusha::vec2i s)
-{
-  glViewport(0, 0, s.x, s.y);
-  viewport_ = kapusha::rect2f(0, (float)s.x, (float)s.y, 0);
-  camera_.setAspect((float)s.x / (float)s.y);
-}
-
-void OpenSource::draw(int ms, float dt)
-{
-  const float speed = 1000.f *
-  (viewctrl_->keyState().isShiftPressed() ? 5.f : 1);
-  camera_.moveForward(forward_speed_ * dt * speed);
-  camera_.moveRigth(right_speed_ * dt * speed);
-  camera_.update();
-
-  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-  for (auto it = levelsv_.begin(); it != levelsv_.end(); ++it)
-    (*it)->draw(camera_);
-
-  if (show_selection_)
-    levelsv_[selection_]->drawContours(camera_);
-  
-  if (forward_speed_ != 0 || right_speed_ != 0)
-    viewctrl_->requestRedraw();
-}
-
-void OpenSource::inputKey(const kapusha::KeyState &keys)
-{
-  using kapusha::KeyState;
-  switch (keys.getLastKey()) {
-    case KeyState::KeyW:
-      forward_speed_ += keys.isLastKeyPressed() ? 1.f : -1.f;
-      break;
-    case KeyState::KeyS:
-      forward_speed_ += keys.isLastKeyPressed() ? -1.f : 1.f;
-      break;
-    case KeyState::KeyA:
-      right_speed_ += keys.isLastKeyPressed() ? -1.f : 1.f;
-      break;
-    case KeyState::KeyD:
-      right_speed_ += keys.isLastKeyPressed() ? 1.f : -1.f;
-      break;
-    case KeyState::KeyZ:
-      if (keys.isLastKeyPressed()) show_selection_ = !show_selection_;
-      break;
-    case KeyState::KeyE:
-      {
-        if (!keys.isLastKeyPressed()) break;
-        ++selection_;
-        selection_ %= levelsv_.size();
-      }
-      break;
-    case KeyState::KeyQ:
-      {
-        if (!keys.isLastKeyPressed()) break;
-        --selection_;
-        if (selection_ < 0) selection_ += levelsv_.size();
-      }
-      break;
-    case KeyState::KeyY:
-      if (keys.isLastKeyPressed()) {
-        levelsv_[selection_]->updateShift(levelsv_[selection_]->shift() - kapusha::vec3f(1.f,0,0)*(keys.isShiftPressed()?100.f:1));
-        L("(%f, %f, %f)", levelsv_[selection_]->shift().x, levelsv_[selection_]->shift().y, levelsv_[selection_]->shift().z);
-        for (auto it = levelsv_.begin(); it != levelsv_.end(); ++it)
-          (*it)->updateShift((*it)->shift());
-      }
-      break;
-    case 'U':
-      if (keys.isLastKeyPressed()) {
-        levelsv_[selection_]->updateShift(levelsv_[selection_]->shift() + kapusha::vec3f(1.f,0,0)*(keys.isShiftPressed()?100.f:1));
-        L("(%f, %f, %f)", levelsv_[selection_]->shift().x, levelsv_[selection_]->shift().y, levelsv_[selection_]->shift().z);
-        for (auto it = levelsv_.begin(); it != levelsv_.end(); ++it)
-          (*it)->updateShift((*it)->shift());
-      }
-      break;
-    case 'H':
-      if (keys.isLastKeyPressed()) {
-        levelsv_[selection_]->updateShift(levelsv_[selection_]->shift() - kapusha::vec3f(0,1.f,0)*(keys.isShiftPressed()?100.f:1));
-        L("(%f, %f, %f)", levelsv_[selection_]->shift().x, levelsv_[selection_]->shift().y, levelsv_[selection_]->shift().z);
-        for (auto it = levelsv_.begin(); it != levelsv_.end(); ++it)
-          (*it)->updateShift((*it)->shift());
-      }
-      break;
-    case 'J':
-      if (keys.isLastKeyPressed()) {
-        levelsv_[selection_]->updateShift(levelsv_[selection_]->shift() + kapusha::vec3f(0,1.f,0)*(keys.isShiftPressed()?100.f:1));
-        L("(%f, %f, %f)", levelsv_[selection_]->shift().x, levelsv_[selection_]->shift().y, levelsv_[selection_]->shift().z);
-        for (auto it = levelsv_.begin(); it != levelsv_.end(); ++it)
-          (*it)->updateShift((*it)->shift());
-      }
-      break;
-    case 'N':
-      if (keys.isLastKeyPressed()) {
-        levelsv_[selection_]->updateShift(levelsv_[selection_]->shift() - kapusha::vec3f(0,0,1.f)*(keys.isShiftPressed()?100.f:1));
-        L("(%f, %f, %f)", levelsv_[selection_]->shift().x, levelsv_[selection_]->shift().y, levelsv_[selection_]->shift().z);
-        for (auto it = levelsv_.begin(); it != levelsv_.end(); ++it)
-          (*it)->updateShift((*it)->shift());
-      }
-      break;
-    case 'm':
-      if (keys.isLastKeyPressed()) {
-        levelsv_[selection_]->updateShift(levelsv_[selection_]->shift() + kapusha::vec3f(0,0,1.f)*(keys.isShiftPressed()?100.f:1));
-        L("(%f, %f, %f)", levelsv_[selection_]->shift().x, levelsv_[selection_]->shift().y, levelsv_[selection_]->shift().z);
-        for (auto it = levelsv_.begin(); it != levelsv_.end(); ++it)
-          (*it)->updateShift((*it)->shift());
-      }
-      break;
-    case KeyState::KeyUp:
-      pitch_speed_ += keys.isLastKeyPressed() ? 1.f : -1.f;
-      break;
-    case KeyState::KeyDown:
-      pitch_speed_ += keys.isLastKeyPressed() ? -1.f : 1.f;
-      break;
-    case KeyState::KeyLeft:
-      yaw_speed_ += keys.isLastKeyPressed() ? 1.f : -1.f;
-      break;
-    case KeyState::KeyRight:
-      yaw_speed_ += keys.isLastKeyPressed() ? -1.f : 1.f;
-      break;
-    case KeyState::KeyEsc:
-      if (keys.isLastKeyPressed())
-      {
-        if (mouselook_)
-        {
-          viewctrl_->limitlessPointer(false);
-          viewctrl_->hideCursor(false);
-          mouselook_ = false;
-        } else
-          viewctrl_->quit(0);
-      }
-      break;
-      
-    default:
-      return;
-  }
-  
-  viewctrl_->requestRedraw();
-}
-
-void OpenSource::inputPointer(const kapusha::PointerState &pointers)
-{
-  if (mouselook_)
-  {
-    camera_.rotatePitch(pointers.main().movement.y);
-    camera_.rotateAxis(kapusha::vec3f(0.f, 0.f, 1.f), -pointers.main().movement.x);
-    viewctrl_->requestRedraw();
-  } else if (pointers.wasPressed())
-  {
-    viewctrl_->limitlessPointer(true);
-    viewctrl_->hideCursor(true);
-    mouselook_ = true;
-  }
-}

+ 0 - 59
src/OpenSource.h

@@ -1,59 +0,0 @@
-#pragma once
-
-#include <string>
-#include <vector>
-#include <deque>
-#include <map>
-#include <unordered_set>
-
-#include <kapusha/core/IViewport.h>
-#include <kapusha/render/Render.h>
-#include <kapusha/render/Camera.h>
-
-#include "ResRes.h"
-
-class BSP;
-
-class OpenSource : public kapusha::IViewport
-{
-public:
-  OpenSource(
-    const char *path,
-    const char *file,
-    int depth = 32);
-  virtual ~OpenSource();
-
-  void addMapRestriction(const std::string& name) {
-    enabled_maps_.insert(name);
-  }
-
-public: // IViewport
-  virtual void init(kapusha::IViewportController *viewctrl);
-  virtual void resize(kapusha::vec2i size);
-  virtual void draw(int ms, float dt);
-  virtual void close() {}
-  virtual void inputPointer(const kapusha::PointerState& pointers);
-  virtual void inputKey(const kapusha::KeyState& keys);
-
-private:
-  kapusha::Render *render_;
-  ResRes resources_;
-  int depth_;
-  kapusha::IViewportController *viewctrl_;
-  std::map<std::string, BSP*> levels_;
-  std::vector<BSP*> levelsv_;
-  std::deque<std::string> maps_to_load_;
-  std::unordered_set<std::string> enabled_maps_;
-  
-  kapusha::rect2f viewport_;
-  kapusha::Camera camera_;
-  float forward_speed_;
-  float right_speed_;
-  float pitch_speed_;
-  float yaw_speed_;
-
-  int selection_;
-  bool show_selection_;
-  
-  bool mouselook_;
-};

+ 0 - 41
src/ResRes.cpp

@@ -1,41 +0,0 @@
-#include <kapusha/core/Core.h>
-#include <kapusha/io/StreamFile.h>
-#include "ResRes.h"
-
-ResRes::ResRes(const char* path)
-  : path_(path)
-{
-}
-
-ResRes::~ResRes(void)
-{
-}
-
-kapusha::StreamSeekable* ResRes::open(const char* name, ResourceType type) const
-{
-  std::string fullpath;
-  switch (type)
-  {
-  case ResourceMap:
-    fullpath = path_ + "/maps/" + name + ".bsp";
-    break;
-  case ResourceTexture:
-    fullpath = path_ + "/materials/" + name + ".vtf";
-    break;
-  default:
-    L("Unsupported resource type %d", type);
-    return 0;
-  }
-
-  if (fullpath.empty())
-    return 0;
-
-  kapusha::StreamFile *stream = new kapusha::StreamFile;
-  if (stream->open(fullpath.c_str()) != kapusha::Stream::ErrorNone)
-  {
-    L("no such resource: %s", fullpath.c_str());
-    delete stream;
-    stream = 0;
-  }
-  return stream;
-}

+ 0 - 28
src/ResRes.h

@@ -1,28 +0,0 @@
-#pragma once
-
-#include <string>
-
-namespace kapusha {
-  class StreamSeekable;
-}
-
-class ResRes
-{
-public:
-  ResRes(const char* path);
-  ~ResRes(void);
-
-  enum ResourceType {
-    ResourceGuess = 0,
-    ResourceMap,
-    ResourceMaterial,
-    ResourceTexture
-  };
-
-  kapusha::StreamSeekable* open(const char* name,
-                                ResourceType type = ResourceGuess) const;
-
-private:
-  std::string path_;
-};
-

+ 0 - 293
src/VTF.cpp

@@ -1,293 +0,0 @@
-#include "VTF.h"
-#include <kapusha/core/Core.h>
-#include <kapusha/core/Log.h>
-#include <kapusha/io/Stream.h>
-#include <kapusha/render/Texture.h>
-
-using namespace kapusha;
-
-#pragma pack(push)
-#pragma pack(1)
-
-struct vtf_file_header_t {
-  char magic[4];
-  u32 version[2];
-  u32 headerSize;
-};
-
-struct vtf_70_header_t {
-  u16 width;
-  u16 height;
-  u32 flags;
-  u16 frames;
-  u16 firstFrame;
-  u8 pad0[4];
-  float reflectivity[3];
-  u8 pad1[4];
-  float bumpmapScale;
-  u32 format;
-  u8 mipmaps;
-  u32 lowresFormat;
-  u8 lowresWidth;
-  u8 lowresHeight;
-  u8 pad2;
-
-  enum Format
-  {
-	  FormatNone = -1,
-  	FormatRGBA8888 = 0,
-	  FormatABGR8888,
-  	FormatRGB888,
-	  FormatBGR888,
-  	FormatRGB565,
-	  FormatI8,
-  	FormatIA88,
-	  FormatP8,
-  	FormatA8,
-	  FormatRGB888Blue,
-  	FormatBGR888Blue,
-	  FormatARGB8888,
-  	FormatBGRA8888,
-	  FormatDXT1,
-  	FormatDXT3,
-	  FormatDXT5,
-  	FormatBGRX8888,
-	  FormatBGR565,
-  	FormatBGRX5551,
-   	FormatBGRA4444,
-	  FormatDXT1Alpha,
-  	FormatBGRA5551,
-	  FormatUV88,
-	  FormatUVWQ8888,
-  	FormatRGBA16161616F,
-	  FormatRGBA16161616,
-	  FormatUVLX8888
-  };
-};
-
-#pragma pack(pop)
-
-unsigned imageSize(u32 format, int width, int height)
-{
-  int pixels = width * height;
-  int pixelsize = 0;
-  switch(format)
-  {
-    case vtf_70_header_t::FormatDXT3:
-    case vtf_70_header_t::FormatDXT5:
-      pixelsize += 8;
-    case vtf_70_header_t::FormatDXT1Alpha:
-    case vtf_70_header_t::FormatDXT1:
-      pixelsize += 8;
-      pixels = (width / 4 + ((width % 4) ? 1 : 0))
-        * (height / 4 + ((height % 4) ? 1 : 0));
-      break;
-
-    case vtf_70_header_t::FormatABGR8888:
-    case vtf_70_header_t::FormatRGBA8888:
-    case vtf_70_header_t::FormatARGB8888:
-    case vtf_70_header_t::FormatBGRA8888:
-    case vtf_70_header_t::FormatBGRX8888:
-    case vtf_70_header_t::FormatUVWQ8888:
-    case vtf_70_header_t::FormatUVLX8888:
-      pixelsize = 4;
-      break;
-
-    case vtf_70_header_t::FormatRGB888:
-	  case vtf_70_header_t::FormatBGR888:
-    case vtf_70_header_t::FormatRGB888Blue:
-    case vtf_70_header_t::FormatBGR888Blue:
-      pixelsize = 3;
-      break;
-
-    default:
-      KP_ASSERT(!"Unsupported format");
-  }
-
-  return pixels * pixelsize;
-}
-
-struct Image : public kapusha::Texture::Meta {
-  u8 *pixels;
-
-  //Image() : width(0), height(0), format(FormatNone), pixels(0) {}
-  Image(int _width, int _height)
-    : Meta(_width, _height, BGRA8888)
-  {
-    pixels = new u8[size.x * size.y * 4];
-  }
-
-  ~Image()
-  {
-    delete pixels;
-  }
-
-  struct ColorRGB565 {
-    u16 c;
-    static const int maskRed = 0xf800;
-    static const int maskGreen = 0x07e0;
-    static const int maskBlue = 0x001f;
-    kapusha::vec4f asRGBAf() const
-    {
-      return kapusha::vec4f((c >> 11) / 31.f,
-                         (((c >> 5)) & 63) / 63.f,
-                         (c & 31) / 31.f,
-                         1.f);
-    }
-    u32 asBGRA32() const {
-      u32 c32 = c;
-      //return 0xff | (c32 & 0xf8) | ((c32 << 13) & 0xfc) | ((c32 << 27) & 0xf8);
-      return 0xff000000 | ((c32 & maskRed) << 8) | ((c32 & maskGreen) << 5) | ((c32 & maskBlue) << 3);
-    }
-    static ColorRGB565 weightedSum(ColorRGB565 a, ColorRGB565 b,
-                                   int A, int B, int D)
-    {
-      u32 
-        aRB = a.c & (maskRed | maskBlue),
-        aG = a.c & maskGreen,
-        bRB = b.c & (maskRed | maskBlue),
-        bG = b.c & maskGreen;
-      //! \todo overflow check? shouldn't happen with A,B,D used here
-      aRB = ((A * aRB + B * bRB) / D) & (maskRed | maskBlue);
-      aG = ((A * aG + B * bG) / D) & maskGreen;
-
-      ColorRGB565 ret;
-      ret.c = aRB | aG;
-      return ret;
-    }
-  };
-
-
-  bool readFromDXT1(kapusha::Stream& stream)
-  {
-    KP_ASSERT(size.x > 0);
-    KP_ASSERT(size.y > 0);
-    KP_ASSERT(format == BGRA8888);
-
-    for (int y = 0; y < size.y; y += 4)
-    {
-      u32 *p = reinterpret_cast<u32*>(pixels) + y * size.x;
-      for (int x = 0; x < size.x; x += 4, p += 4)
-      {
-        struct {
-          ColorRGB565 c[2];
-          u8 map[4];
-        } chunk;
-        u32 c[4];
-        if (Stream::ErrorNone != stream.copy(&chunk, 8))
-          return false;
-        c[0] = chunk.c[0].asBGRA32();
-        c[1] = chunk.c[1].asBGRA32();
-
-        if (chunk.c[0].c > chunk.c[1].c)
-        {
-          c[2] = ColorRGB565::weightedSum(chunk.c[0], chunk.c[1], 
-                                          2, 1, 3).asBGRA32();
-          c[3] = ColorRGB565::weightedSum(chunk.c[0], chunk.c[1],
-                                          1, 2, 3).asBGRA32();
-        } else {
-          c[2] = ColorRGB565::weightedSum(chunk.c[0], chunk.c[1],
-                                          1, 1, 2).asBGRA32();
-          c[3] = 0;
-        }
-
-        u32* pp = p;
-        for(int row = 0; row < 4 && ((row+y) < size.y); ++row, pp += size.x-4)
-        {
-          *pp++ = c[chunk.map[row] >> 6];
-          if(x+1 < size.x) *pp = c[(chunk.map[row] >> 4) & 3];
-          ++pp;
-          if(x+2 < size.x) *pp = c[(chunk.map[row] >> 2) & 3];
-          ++pp;
-          if(x+3 < size.x) *pp = c[chunk.map[row] & 3];
-          ++pp;
-        }
-      }
-    }
-
-    return true;
-  }
-};
-
-VTF::VTF(void)
-{
-}
-
-VTF::~VTF(void)
-{
-}
-
-kapusha::Texture *VTF::load(kapusha::StreamSeekable& stream)
-{
-  vtf_file_header_t file_header;
-  if(Stream::ErrorNone != stream.copy(&file_header, sizeof file_header))
-  {
-    return 0;
-  }
-  
-  if (file_header.magic[0] != 'V' || file_header.magic[1] != 'T' || 
-      file_header.magic[2] != 'F' || file_header.magic[3] != 0)
-      return 0;
-
-  L("vtf image ver %d.%d", file_header.version[0], file_header.version[1]);
-  if (!(file_header.version[0] == 7 && (file_header.version[1] == 0 || file_header.version[1] == 1)))
-  {
-    L("versions other than 7.0, 7.1 are not supported");
-    return 0;
-  }
-
-  vtf_70_header_t header;
-  int szh = sizeof(header), szfh = sizeof(file_header);
-  L("%d %d", szh, szfh);
-  KP_ENSURE(Stream::ErrorNone == stream.copy(&header, sizeof header));
-  KP_ASSERT(file_header.headerSize == (sizeof(header) + sizeof(file_header)));
-
-  L("\timage format %d size %dx%d",
-    header.format, header.width, header.height);
-  L("\tflags %08x", header.flags);
-  L("\tframes %d->%d", header.firstFrame, header.frames);
-  L("\treflect %f %f %f, bump %f",
-    header.reflectivity[0], header.reflectivity[1], header.reflectivity[2],
-    header.bumpmapScale);
-
-  L("\tlowres image format %d size %dx%d",
-    header.lowresFormat, header.lowresWidth, header.lowresHeight);
-  KP_ASSERT(header.lowresFormat == vtf_70_header_t::FormatDXT1);
-  Image lowres(header.lowresWidth, header.lowresHeight);
-  KP_ENSURE(lowres.readFromDXT1(stream));
-  kapusha::Texture *ret = new kapusha::Texture();
-
-  // skip everything until last one
-  KP_ASSERT((header.flags & 0x4000) == 0); //! \todo envmap support
-  for (int mipmap = header.mipmaps; mipmap > 0; --mipmap)
-    for (int frame = header.firstFrame; frame <= header.frames; ++frame)
-      for (int face = 0; face < 1; ++face)
-        for (int depth = 0; depth < 1; ++depth) //! \todo layers support
-        {
-          stream.read(imageSize(header.format,
-                      header.width >> mipmap, header.height >> mipmap));
-          KP_ASSERT(kapusha::Stream::ErrorNone == stream.error_);
-        }
-
-  if (header.format == vtf_70_header_t::FormatDXT1)
-  {
-    Image image(header.width, header.height);
-    KP_ENSURE(image.readFromDXT1(stream));
-    ret->upload(image, image.pixels);
-  } else if (header.format == vtf_70_header_t::FormatBGRX8888)
-  {
-    Image image(header.width, header.height);
-    KP_ENSURE(kapusha::Stream::ErrorNone == 
-      stream.copy(image.pixels,
-                  imageSize(header.width, header.height, header.format)));
-    ret->upload(image, image.pixels);
-  } else
-  {
-    L("Unsupported image format %d, using dxt1 thumbnail", header.format);
-    ret->upload(lowres, lowres.pixels);
-  }
-
-  size_.x = header.width;
-  size_.y = header.height;
-  return ret;
-}

+ 0 - 21
src/VTF.h

@@ -1,21 +0,0 @@
-#pragma once
-#include <kapusha/math/types.h>
-
-namespace kapusha {
-  class StreamSeekable;
-  class Texture;
-}
-
-class VTF
-{
-public:
-  VTF(void);
-  ~VTF(void);
-
-  kapusha::Texture *load(kapusha::StreamSeekable& stream);
-  kapusha::vec2i size() const { return size_; }
-
-private:
-  kapusha::vec2i size_;
-};
-

+ 0 - 0
ahash.h → src/ahash.h


+ 0 - 0
atlas.c → src/atlas.c


+ 0 - 0
atlas.h → src/atlas.h


+ 0 - 0
3p/atto → src/atto


+ 0 - 0
bsp.c → src/bsp.c


+ 0 - 0
bsp.h → src/bsp.h


+ 0 - 0
cache.c → src/cache.c


+ 0 - 0
cache.h → src/cache.h


+ 0 - 0
collection.c → src/collection.c


+ 0 - 0
collection.h → src/collection.h


+ 0 - 0
common.h → src/common.h


+ 0 - 0
dxt.c → src/dxt.c


+ 0 - 0
dxt.h → src/dxt.h


+ 0 - 0
filemap.c → src/filemap.c


+ 0 - 0
filemap.h → src/filemap.h


+ 0 - 0
libc.h → src/libc.h


+ 0 - 0
material.c → src/material.c


+ 0 - 0
material.h → src/material.h


+ 0 - 0
mempools.h → src/mempools.h


+ 0 - 0
texture.c → src/texture.c


+ 0 - 0
texture.h → src/texture.h


+ 0 - 0
vbsp.h → src/vbsp.h


+ 0 - 0
vtf.h → src/vtf.h