Skip to content

Commit

Permalink
improve modular (cocos#3069)
Browse files Browse the repository at this point in the history
* improve modular

* fixed test

* remove previousRequire from engine prelude
  • Loading branch information
2youyou2 authored and pandamicro committed Aug 10, 2018
1 parent 5114513 commit a4d17d3
Show file tree
Hide file tree
Showing 12 changed files with 374 additions and 361 deletions.
5 changes: 3 additions & 2 deletions cocos2d/core/CCGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require('../audio/CCAudioEngine');
const debug = require('./CCDebug');
const renderer = require('./renderer/index.js');
const inputManager = CC_QQPLAY ? require('./platform/BKInputManager') : require('./platform/CCInputManager');
const dynamicAtlasManager = require('../core/renderer/utils/dynamic-atlas/manager');

/**
* @module cc
Expand Down Expand Up @@ -735,8 +736,8 @@ var game = {
this._renderContext = renderer.device._gl;

// Enable dynamic atlas manager by default
if (!cc.macro.CLEANUP_IMAGE_CACHE) {
cc.dynamicAtlasManager.enabled = true;
if (!cc.macro.CLEANUP_IMAGE_CACHE && dynamicAtlasManager) {
dynamicAtlasManager.enabled = true;
}
}
if (!this._renderContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {
// TODO: Material API design and export from editor could affect the material activation process
// need to update the logic here
if (frame) {
if (!frame._original) {
if (!frame._original && dynamicAtlasManager) {
dynamicAtlasManager.insertSpriteFrame(frame);
}
if (!sprite._material || sprite._material._texture !== frame._texture) {
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/renderer/webgl/assemblers/sprite/mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const dynamicAtlasManager = require('../../../utils/dynamic-atlas/manager');
// TODO: Material API design and export from editor could affect the material activation process
// need to update the logic here
if (frame) {
if (!frame._original) {
if (!frame._original && dynamicAtlasManager) {
dynamicAtlasManager.insertSpriteFrame(frame);
}
if (!sprite._material || sprite._material._texture !== frame._texture) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = {
// TODO: Material API design and export from editor could affect the material activation process
// need to update the logic here
if (frame) {
if (!frame._original) {
if (!frame._original && dynamicAtlasManager) {
dynamicAtlasManager.insertSpriteFrame(frame);
}
if (!sprite._material || sprite._material._texture !== frame._texture) {
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/renderer/webgl/assemblers/sprite/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
// TODO: Material API design and export from editor could affect the material activation process
// need to update the logic here
if (frame) {
if (!frame._original) {
if (!frame._original && dynamicAtlasManager) {
dynamicAtlasManager.insertSpriteFrame(frame);
}
if (!sprite._material || sprite._material._texture !== frame._texture) {
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/renderer/webgl/assemblers/sprite/sliced.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {
// TODO: Material API design and export from editor could affect the material activation process
// need to update the logic here
if (frame) {
if (!frame._original) {
if (!frame._original && dynamicAtlasManager) {
dynamicAtlasManager.insertSpriteFrame(frame);
}
if (!sprite._material || sprite._material._texture !== frame._texture) {
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/renderer/webgl/assemblers/sprite/tiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = {
// TODO: Material API design and export from editor could affect the material activation process
// need to update the logic here
if (frame) {
if (!frame._original) {
if (!frame._original && dynamicAtlasManager) {
dynamicAtlasManager.insertSpriteFrame(frame);
}
if (!sprite._material || sprite._material._texture !== frame._texture) {
Expand Down
7 changes: 5 additions & 2 deletions cocos2d/core/renderer/webgl/render-component-walker.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const macro = require('../../platform/CCMacro');
const renderEngine = require('../render-engine');
const defaultVertexFormat = require('./vertex-format').vfmtPosUv;
const StencilManager = require('./stencil-manager');
const atlasManager = require('../utils/dynamic-atlas/manager');
const dynamicAtlasManager = require('../utils/dynamic-atlas/manager');
const RenderFlow = require('../render-flow');
const QuadBuffer = require('./quad-buffer');
const MeshBuffer = require('./mesh-buffer');
Expand Down Expand Up @@ -212,7 +212,10 @@ RenderComponentWalker.prototype = {

RenderFlow.render(scene);

atlasManager.update();
if (dynamicAtlasManager) {
dynamicAtlasManager.update();
}

this._flush();

for (let key in _buffers) {
Expand Down
13 changes: 2 additions & 11 deletions gulp/browserify_prelude.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
// orig method which is the requireuire for previous bundles

(function outer (modules, cache, entry) {
// Save the require from previous bundle to this closure if any
var previousRequire = typeof require == "function" && require;

function newRequire(name, jumped){
var module = cache[name];
if(!module) {
Expand All @@ -24,14 +21,8 @@
var currentRequire = typeof require == "function" && require;
if (!jumped && currentRequire) return currentRequire(name, true);

// If there are other bundles on this page the require from the
// previous one is saved to 'previousRequire'. Repeat this as
// many times as there are bundles until the module is found or
// we exhaust the require chain.
if (previousRequire) return previousRequire(name, true);
var err = new Error('Cannot find module \'' + name + '\'');
err.code = 'MODULE_NOT_FOUND';
throw err;
// this module is excluded from engine
return undefined;
}
var exports = {};
module = cache[name] = {exports: exports};
Expand Down
14 changes: 7 additions & 7 deletions gulp/tasks/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ exports.buildCocosJs = function (sourceFile, outputFile, excludes, opt_macroFlag
var bundler = createBundler(sourceFile, opts);

excludes && excludes.forEach(function (file) {
bundler.ignore(file);
bundler.exclude(file);
});

bundler = bundler.bundle();
Expand Down Expand Up @@ -118,10 +118,10 @@ exports.buildCocosJsMin = function (sourceFile, outputFile, excludes, opt_macroF
var bundler = createBundler(sourceFile, opts);

excludes && excludes.forEach(function (file) {
bundler.ignore(file);
bundler.exclude(file);
});

bundler.ignore(Path.resolve(__dirname, '../../DebugInfos.json'));
bundler.exclude(Path.resolve(__dirname, '../../DebugInfos.json'));

var Size = null;
try {
Expand Down Expand Up @@ -212,7 +212,7 @@ exports.buildJsbPreview = function (sourceFile, outputFile, excludes, callback)

var bundler = createBundler(sourceFile);
excludes.forEach(function (module) {
bundler.ignore(require.resolve(module));
bundler.exclude(require.resolve(module));
});
bundler.bundle()
.on('error', HandleErrors.handler)
Expand Down Expand Up @@ -249,7 +249,7 @@ exports.buildJsb = function (sourceFile, outputFile, excludes, opt_macroFlags, c
var bundler = createBundler(sourceFile, opts);
excludes = excludes.concat(jsbSkipModules);
excludes.forEach(function (module) {
bundler.ignore(require.resolve(module));
bundler.exclude(require.resolve(module));
});
bundler.bundle()
.on('error', HandleErrors.handler)
Expand Down Expand Up @@ -286,10 +286,10 @@ exports.buildJsbMin = function (sourceFile, outputFile, excludes, opt_macroFlags
var bundler = createBundler(sourceFile, opts);
excludes = excludes.concat(jsbSkipModules);
excludes.forEach(function (module) {
bundler.ignore(require.resolve(module));
bundler.exclude(require.resolve(module));
});

bundler.ignore(Path.resolve(__dirname, '../../DebugInfos.json'));
bundler.exclude(Path.resolve(__dirname, '../../DebugInfos.json'));

bundler.bundle()
.on('error', HandleErrors.handler)
Expand Down
14 changes: 14 additions & 0 deletions modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@
"./extensions/dragonbones/webgl-assembler.js"
]
},
{
"name": "Renderer Texture",
"entries": [
"./cocos2d/core/assets/CCRenderTexture.js"
],
"dependencies": ["WebGL Renderer"]
},
{
"name": "Dynamic Atlas",
"entries": [
"./cocos2d/core/renderer/utils/dynamic-atlas/manager.js"
],
"dependencies": ["Renderer Texture"]
},
{
"name": "LabelOutline",
"entries": [
Expand Down
Loading

0 comments on commit a4d17d3

Please sign in to comment.